Raml\ApiDefinition::getResourceByUri PHP Method

getResourceByUri() public method

Get a resource by a uri
public getResourceByUri ( string $uri ) : Raml\Resource
$uri string
return Raml\Resource
    public function getResourceByUri($uri)
    {
        // get rid of everything after the ?
        $uri = strtok($uri, '?');
        $resources = $this->getResourcesAsArray($this->resources);
        foreach ($resources as $resource) {
            if ($resource->matchesUri($uri)) {
                return $resource;
            }
        }
        // we never returned so throw exception
        throw new ResourceNotFoundException($uri);
    }

Usage Example

 /**
  * @param string $path
  * @return \Raml\Resource
  * @throws ValidatorSchemaException
  */
 private function getResource($path)
 {
     try {
         return $this->apiDefinition->getResourceByUri($path);
     } catch (ResourceNotFoundException $exception) {
         $message = sprintf('Schema for URI %s was not found in API definition', $path);
         throw new ValidatorSchemaException($message, 0, $exception);
     }
 }
All Usage Examples Of Raml\ApiDefinition::getResourceByUri