Services
- Services as Constants
- FactoryDefault DI
- Custom Services
- Request
- Response
- User Service
- Authentication Manager
- Fractal Manager
- Token Parser
- Query
- PHQL Query Parser
- URL Query Parser
Services as Constants
Each name of the service that gets registered in the FactoryDefault
DI of Prest is defined as a constant. This keeps your code organized and provides autocompletion.
Throughout the library we use it as follows:
use PhalconRest\Constants\Services;
FactoryDefault DI
Like Phalcon we provide you with a FactoryDefault
DI with all services registered.
$di = new Prest\Di\FactoryDefault;
Custom Services
Note that you can always extend from these services and register your own version using the same name. This way Prest will use your version.
Request
This service adds some convenience methods. Like Prest\Http\Request::getToken
to get the authentication token from either a query parameter or Authorization header.
$request = $di->get(Services::REQUEST);
Response
This service is mainly responsible for outputting JSON formatted errors and data responses in a consistent way.
$response = $di->get(Services::RESPONSE);
User Service
Provides initial service to work with User model. Usually this service have to be extend to amend with domain specific logic.
$userService = $di->get(Services::USER_SERVICE);
Authentication Manager
This service allows to authenticate using different account types or using a token and getting session info.
$authenticationManager = $di->get(Services::AUTH_MANAGER);
Fractal Manager
This service is from a third-party library called Fractal, it provides us with a transformation layer for complex data output.
$fractalManager = $di->get(Services::FRACTAL_MANAGER);
Token Parser
This service is responsible for parsing session tokens. At the moment we provide a Json Web Token Parser (Prest\Auth\TokenParsers\JWTTokenParser
). You are free to replace this with your own token parser.
$tokenParser = $di->get(Services::TOKEN_PARSER);
Query
This is a global instance of Prest\Data\Query
. It gets configured on each request by Prest\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.
$query = $di->get(Services::QUERY);
PHQL Query Parser
This service provides a way to apply all options in a Prest\Data\Query
instance to a Phalcon\Mvc\Model\Query\Builder
instance.
$phqlQueryParser = $di->get(Services::PHQL_QUERY_PARSER);
URL Query Parser
This service is used internally to parse GET
parameters to the Prest\Data\Query
instance which is stored globally.
$urlQueryParser = $di->get(AppServices::URL_QUERY_PARSER);