Download the PHP package pitch/symfony-adr without Composer
On this page you can find all versions of the php package pitch/symfony-adr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pitch/symfony-adr
More information about pitch/symfony-adr
Files in pitch/symfony-adr
Package symfony-adr
Short Description This bundle makes it easier to follow ADR pattern while writing a Symfony application
License MIT
Informations about the package symfony-adr
ADR Bundle for Symfony
This bundle makes it easier to follow ADR pattern while writing a Symfony application.
Usage
Turn controller into action
Decouple responder logic from action logic by moving it out of the controller. Just return the payload!
If a controller returns anything but a Response
object,
Symfony dispatches a kernel.view
event.
Now instead of registering a bunch of event listeners to be iterated through,
implement ResponseHandlerInterface
.
If your handler class is available as a service according to your config/services.yaml
,
it will be discovered and used whenever a MyPayload
object is returned by a controller.
With default config just put the class into src/Responder/MyPayloadHandler.php
and you are done.
Your response handler can report its priority in getSupportedTypes
.
Or you can overwrite the handled types and priorities for response handlers in your services.yml
.
You can easily debug your responder config per console command.
Treat some exceptions as response payload
A robust domain will have strict constraints and throw exceptions whenever an unexpected or invalid condition occurs
and for every exception falling through your controller/action Symfony dispatches a kernel.exception
event.
You can reserve this event for truly unexpected behavior without repeating similar try-catch-blocks across your controllers.
Define which exceptions should be catched for all controllers and be treated as response payload:
If Doctrine Annotations is installed, you can define extra rules for your controller methods per annotation:
With PHP8 you can define extra rules per Attribute:
Rules are applied in the order of appearance, method rules after global rules.
Now you can just create a App\Responder\MyGoodRuntimeExceptionHandler
as described above.
Default response handlers
The bundle automatically adds some response handlers for basic types with negative priority so that they will be called if none of your response handlers stops propagation earlier. If you don't want the default handlers to be added, you can modify this behavior per bundle configuration.
Prioritised response handlers
If consecutive response handlers (in the order of config priority) implement PrioritisedResponseHandlerInterface
, that block of handlers will be reordered on runtime according the priority they report for the specific request per getResponseHandlerPriority
.
Negotiating content type in response handlers
See JsonResponder
on how to implement your own prioritised response handlers that handle a payload according to the Accept header on the request.
You can set a default content type for requests that don't include an Accept header. This can be done per container parameter or as controller annotation.
All versions of symfony-adr with dependencies
composer/composer Version ^1 || ^2
pitch/annotation Version ^1.0
symfony/config Version ^5.4.9 || ^6
symfony/dependency-injection Version ^5.4.9 || ^6
symfony/http-kernel Version ^5.4.9 || ^6