Use this middleware as the outermost (or close to outermost) middleware
layer, and use it to intercept PHP errors and exceptions.
The class offers two extension points:
- Error response generators.
- Listeners.
Error response generators are callables with the following signature:
function (
Throwable|Exception $e,
ServerRequestInterface $request,
ResponseInterface $response
) : ResponseInterface
These are provided the error, and the request responsible; the response
provided is the response prototype provided to the ErrorHandler instance
itself, and can be used as the basis for returning an error response.
An error response generator must be provided as a constructor argument;
if not provided, an instance of Zend\Stratigility\Middleware\ErrorResponseGenerator
will be used.
Listeners use the following signature:
function (
Throwable|Exception $e,
ServerRequestInterface $request,
ResponseInterface $response
) : void
Listeners are given the error, the request responsible, and the generated
error response, and can then react to them. They are best suited for
logging and monitoring purposes.
Listeners are attached using the attachListener() method, and triggered
in the order attached.