auto1-oss / service-api-components-bundle
Auto1 Common Components for Service API/Client/Handler Bundles
Installs: 71 270
Dependents: 2
Suggesters: 0
Security: 0
Stars: 5
Watchers: 5
Forks: 12
Open Issues: 1
Type:auto1-bundle
Requires
- php: >=7.1.3
- auto1-oss/service-api-request: ^1.0
- fig/http-message-util: ^1.1.2
- monolog/monolog: ~1.22
- symfony/config: ~4.0|~5.0|~6.0
- symfony/dependency-injection: ~4.0|~5.0|~6.0
- symfony/http-kernel: ~4.0|~5.0|~6.0
- symfony/monolog-bridge: ~4.0|~5.0|~6.0
- symfony/property-access: ~4.0|~5.0|~6.0
- symfony/property-info: ~4.0|~5.0|~6.0
- symfony/serializer: ~4.2|~5.0|~6.0
- symfony/yaml: ~4.0|~5.0|~6.0
Requires (Dev)
- phpspec/prophecy-phpunit: ^1.1
- phpunit/phpunit: ^7.5|^8.0|^9.0
- symfony/console: ~3.0|~4.0|~5.0|~6.0
README
config.yml
framework: serializer: { enabled: true } property_info: { enabled: true }
Example EP Provider symfony.service declaration:
tag
{ name: 'auto1.api.endpoint_provider', priority: 0 }
services.yml
services: your_app.api.endpoint.provider: class: Auto1\ServiceAPIComponentsBundle\Service\Endpoint\EndpointProviderConfiguration arguments: - '@auto1.api.endpoint.factory' - '@your_app.api.endpoint_configuration.loader' tags: - { name: 'auto1.api.endpoint_provider', priority: 0 } your_app.api.endpoint_configuration.loader: class: Auto1\ServiceAPIComponentsBundle\Service\Endpoint\EndpointsConfigurationLoader arguments: - '%kernel.project_dir%/src/Resources/endpoints.yml'
Super Quick Start:
Only for proof of concept etc.
class YourProvider implements EndpointProviderInterface { public function getEndpoints(): array { return [ new EndpointImmutable( ..., ), ]; } }
services: your_app.api.endpoint.provider: class: YourProvider tags: - { name: 'auto1.api.endpoint_provider', priority: 0 }
Example of EP definition (yaml):
# Auth - method: 'POST' baseUrl: '%wkda.java_api.url%' path: '/v1/auth/oauth/token' requestFormat: 'url' requestClass: 'Auto1\ServiceDTOCollection\Authentication\OAuth\Request\PostRefreshTokenRequest' responseClass: 'Auto1\ServiceDTOCollection\Authentication\OAuth\Response\Token' - method: 'GET' baseUrl: '%wkda.java_api.admin_url%' path: '/v1/auth/user/admin/{userUuid}/roles' requestFormat: 'url' requestClass: 'Auto1\ServiceDTOCollection\Authentication\User\Request\GetUserRolesRequest' responseClass: 'Auto1\ServiceDTOCollection\Authentication\User\Response\UserRoles' # CarLead - method: 'GET' baseUrl: '%wkda.java_api.url%' path: '/v1/carlead/vin/{vin}' requestClass: 'Auto1\ServiceDTOCollection\CarLead\CarLeadRead\Request\GetCarDetailsByVinRequest' responseClass: 'Auto1\ServiceDTOCollection\CarLead\CarLeadRead\Response\CarLead[]'
Alternative:
# Auth refreshToken: method: 'POST' baseUrl: '%wkda.java_api.url%' path: '/v1/auth/oauth/token' requestFormat: 'url' requestClass: 'Auto1\ServiceDTOCollection\Authentication\OAuth\Request\PostRefreshTokenRequest' responseClass: 'Auto1\ServiceDTOCollection\Authentication\OAuth\Response\Token' getUserRoles: method: 'GET' baseUrl: '%wkda.java_api.admin_url%' path: '/v1/auth/user/admin/{userUuid}/roles' requestFormat: 'url' requestClass: 'Auto1\ServiceDTOCollection\Authentication\User\Request\GetUserRolesRequest' responseClass: 'Auto1\ServiceDTOCollection\Authentication\User\Response\UserRoles' # CarLead getCarLeadByVin: method: 'GET' baseUrl: '%wkda.java_api.url%' path: '/v1/carlead/vin/{vin}' requestClass: 'Auto1\ServiceDTOCollection\CarLead\CarLeadRead\Request\GetCarDetailsByVinRequest' responseClass: 'Auto1\ServiceDTOCollection\CarLead\CarLeadRead\Response\CarLead[]'
Example of ServiceRequest implementation:
class GetCarDetailsByVinRequest implements ServiceRequestInterface { private $vin; public function setVin(string $vin): self { $this->vin = $vin; return $this; } public function getVin() { return $this->vin; } }
Url resolution
For altering the default behaviour of Url resolution see UrlResolverCompilerPass
and use auto1.api.url_resolver
tag together with priority
:
# this is a default resolver auto1.api.url_resolver.parameter_aware: class: Auto1\ServiceAPIComponentsBundle\Service\UrlResolver\ParameterAwareUrlResolver arguments: - '@service_container' tags: - { name: 'auto1.api.url_resolver', priority: 0 }
Debug:
To output all registered endpoints:
bin/console auto1.debug.endpoints