Download the PHP package germania-kg/responder without Composer
On this page you can find all versions of the php package germania-kg/responder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download germania-kg/responder
More information about germania-kg/responder
Files in germania-kg/responder
Package responder
Short Description Responder interfaces and classes for ADR pattern
License MIT
Informations about the package responder
Germania KG · Responder
Installation
Responder classes
- TwigResponder
- JsonResponder
- ErrorResponder
Interfaces
ResponderInterface
The Germania\Responder\ResponderInterface
provides a createResponse method which accepts data to create a PSR-7 responde from. The data can be of any type.
Implementing classes must also be callable and implement an invoke function with same signature.
- Should throw ResponderInvalidArgumentException when passed data is incorrect.
- Should throw ResponderRuntimeException when s.th. bad happens underway.
ResponderExceptionInterface
The Germania\Responder\ResponderExceptionInterface
is the base interface all Responder exceptions have in common. See Exceptions section.
TwigResponder
The constructor accepts a Twig Environment, the name of the array field which holds the template, and optionally a default context variables array.
You can optionally pass a custom PSR-17 Response Factory, per default the Response factory from slim/psr7 will be used.
The template $data
passed to createResponse method will be merged with $default_context
.
Setup
Configuration
Usage
JsonResponder
Creates a JSON response from the given data. Implements ResponderInterface.
Responses will have Content-type: application/json
.
You can optionally pass a custom PSR-17 Response Factory, per default the Response factory from slim/psr7 will be used.
Setup
Configuration
Usage
CallbackResponder
This class applies a callback to the given data before passing to any inner responder which must be instance of ResponderInterface.
Configuration
NoContentResponder
Produced empty responses with 204 status.
ErrorResponder
The ErrorResponder mangles Throwables and acts as decorator for another ResponderInterface. It extends from ResponderDecoratorAbstract and implements ResponderInterface.
The error passed to createResponse is converted to an array with an errors
element that contains the error and all its previous errors (depending on debug
mode). The array will then be passed to the inner responder.
The default response status code is 500
and can be adjusted on call.
Extends from ResponderDecoratorAbstract and implements ResponderInterface.
Setup
Configuration
Usage
Optionally pass a custom status code; default is 500
.
Response Examples
These examples assume a JsonResponder
was used as inner responder. Note the errors
element: it contains the error object, and optionally, its previous errors.
When debug is TRUE
, previous exceptions are included, and the location of the occurrence:
Exceptions
- Germania\Responder\ResponderExceptionInterface
- Germania\Responder\ResponderInvalidArgumentException extends \InvalidArgumentException and implements ResponderExceptionInterface.
- Germania\Responder\ResponderRuntimeException extends \RuntimeException and implements ResponderExceptionInterface.
Example: Deal with errors
Traits
ResponderTrait
Use the Germania\Responder\ResponderTrait
in your classes:
ResponseFactoryTrait
TwigResponder and JsonResponder use the Germania\Responder\ResponseFactoryTrait
. Per default they use the Response factory from nyholm/psr7.