httpsoft / http-error-handler
Error handling PSR-7 and PSR-15 components
Installs: 16 945
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0
- httpsoft/http-response: ^1.1
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- httpsoft/http-server-request: ^1.1
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^4.9|^5.2
README
This package implements Psr\Http\Server\MiddlewareInterface and Psr\Http\Server\RequestHandlerInterface.
Documentation
Installation
This package requires PHP version 7.4 or later.
composer require httpsoft/http-error-handler
Usage ErrorHandler
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);
Usage ErrorHandlerMiddleware
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);