This package implements Psr\Http\Server\MiddlewareInterface and Psr\Http\Server\RequestHandlerInterface.
This package requires PHP version 7.4 or later.
composer require httpsoft/http-error-handler
use HttpSoft\ErrorHandler\ErrorHandler;
/**
* @var Psr\Http\Message\ServerRequestInterface $request
* @var Psr\Http\Server\RequestHandlerInterface $handler
*
* @var HttpSoft\ErrorHandler\ErrorListenerInterface $logErrorListener
* @var HttpSoft\ErrorHandler\ErrorListenerInterface $sendErrorListener
* @var HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface $responseGenerator
*/
$errorHandler = new ErrorHandler($handler, $responseGenerator);
$errorHandler->addListener($logErrorListener);
$errorHandler->addListener($sendErrorListener);
/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $errorHandler->handle($request);
use HttpSoft\ErrorHandler\ErrorHandlerMiddleware;
/**
* @var Psr\Http\Message\ServerRequestInterface $request
* @var Psr\Http\Server\RequestHandlerInterface $handler
*
* @var HttpSoft\ErrorHandler\ErrorListenerInterface $logErrorListener
* @var HttpSoft\ErrorHandler\ErrorListenerInterface $sendErrorListener
* @var HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface $responseGenerator
*/
$errorHandler = new ErrorHandlerMiddleware($responseGenerator);
$errorHandler->addListener($logErrorListener);
$errorHandler->addListener($sendErrorListener);
/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $errorHandler->process($request, $handler);