Resources are a quick way to define endpoint collections.
- Services as Constants
- Factory Default DI
- Custom Services
- Authentication Manager
- Fractal Manager
- Token Parser
- API Service
- PHQL Query Parser
- URL Query Parser
Services as Constants
Each name of the service that gets registered in the Factory Default DI of Phalcon REST is defined as a constant. This keeps your code organized and provides autocompletion.
Throughout the library we use it as follows:
Factory Default DI
Like Phalcon we provide you with a Factory Default DI with all services registered.
$di = new \PhalconRest\Di\FactoryDefault;
Note that you can always extend from these services and register your own version using the same name. This way Phalcon REST will use your version.
$request = $di->get(Services::REQUEST);
This service adds some convenience methods. Like
getToken() to get the authentication token from either a query parameter or Authorization header.
$response = $di->get(Services::RESPONSE);
This service is mainly responsible for outputting json formatted errors and data responses in a consistent way.
$authenticationManager = $di->get(Services::AUTH_MANAGER);
This service allows to authenticate using different account types or using a token and getting session info.
$fractalManager = $di->get(Services::FRACTAL_MANAGER);
This service is from a third-party library called Fractal, it provides us with a transformation layer for complex data output.
$tokenParser = $di->get(Services::TOKEN_PARSER);
This service is responsible for parsing session tokens.
At the moment we provide a Json Web Token Parser (
\PhalconRest\Auth\TokenParser\JWT). You are free to replace this with your own token parser.
$query = $di->get(Services::QUERY);
This is a global instance of
\PhalconRest\Data\Query. It gets configured on each request by
\PhalconRest\Middleware\UrlQuery. It's purpose is to provide a layer between the URL Query Syntax and another Query Syntax you prefer. This object can for instance be parsed to a PHQL query.
PHQL Query Parser
$phqlQueryParser = $di->get(Services::PHQL_QUERY_PARSER);
This service provides a way to apply all options in a
\PhalconRest\Data\Query instance to a
URL Query Parser
$urlQueryParser = $di->get(AppServices::URL_QUERY_PARSER);
This service is used internally to parse GET parameters to the
\PhalconRest\Data\Query instance which is stored globally.