|
1 | 1 | # HTTP Error Handler
|
2 | 2 |
|
3 |
| -The repository is under development, and the description will appear later. |
| 3 | +[](https://packagist.org/packages/httpsoft/http-error-handler) |
| 4 | +[](https://packagist.org/packages/httpsoft/http-error-handler) |
| 5 | +[](https://packagist.org/packages/httpsoft/http-error-handler) |
| 6 | +[](https://github.com/httpsoft/http-error-handler/actions) |
| 7 | +[](https://scrutinizer-ci.com/g/httpsoft/http-error-handler/?branch=master) |
| 8 | +[](https://scrutinizer-ci.com/g/httpsoft/http-error-handler/?branch=master) |
| 9 | + |
| 10 | +This package implements [Psr\Http\Server\MiddlewareInterface](https://github.com/php-fig/http-server-middleware/blob/master/src/MiddlewareInterface.php) and [Psr\Http\Server\RequestHandlerInterface](https://github.com/php-fig/http-server-handler/blob/master/src/RequestHandlerInterface.php). |
| 11 | + |
| 12 | +## Documentation |
| 13 | + |
| 14 | +* [In English language](https://httpsoft.org/docs/error-handler). |
| 15 | +* [In Russian language](https://httpsoft.org/ru/docs/error-handler). |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +This package requires PHP version 7.4 or later. |
| 20 | + |
| 21 | +``` |
| 22 | +composer require httpsoft/http-error-handler |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage ErrorHandler |
| 26 | + |
| 27 | +```php |
| 28 | +use HttpSoft\ErrorHandler\ErrorHandler; |
| 29 | + |
| 30 | +/** |
| 31 | + * @var Psr\Http\Message\ServerRequestInterface $request |
| 32 | + * @var Psr\Http\Server\RequestHandlerInterface $handler |
| 33 | + * |
| 34 | + * @var HttpSoft\ErrorHandler\ErrorListenerInterface $logErrorListener |
| 35 | + * @var HttpSoft\ErrorHandler\ErrorListenerInterface $sendErrorListener |
| 36 | + * @var HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface $responseGenerator |
| 37 | + */ |
| 38 | + |
| 39 | +$errorHandler = new ErrorHandler($handler, $responseGenerator); |
| 40 | + |
| 41 | +$errorHandler->addListener($logErrorListener); |
| 42 | +$errorHandler->addListener($sendErrorListener); |
| 43 | + |
| 44 | +/** @var \Psr\Http\Message\ResponseInterface $response */ |
| 45 | +$response = $errorHandler->handle($request); |
| 46 | +``` |
| 47 | + |
| 48 | +## Usage ErrorHandlerMiddleware |
| 49 | + |
| 50 | +```php |
| 51 | +use HttpSoft\ErrorHandler\ErrorHandlerMiddleware; |
| 52 | + |
| 53 | +/** |
| 54 | + * @var Psr\Http\Message\ServerRequestInterface $request |
| 55 | + * @var Psr\Http\Server\RequestHandlerInterface $handler |
| 56 | + * |
| 57 | + * @var HttpSoft\ErrorHandler\ErrorListenerInterface $logErrorListener |
| 58 | + * @var HttpSoft\ErrorHandler\ErrorListenerInterface $sendErrorListener |
| 59 | + * @var HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface $responseGenerator |
| 60 | + */ |
| 61 | + |
| 62 | +$errorHandler = new ErrorHandlerMiddleware($responseGenerator); |
| 63 | + |
| 64 | +$errorHandler->addListener($logErrorListener); |
| 65 | +$errorHandler->addListener($sendErrorListener); |
| 66 | + |
| 67 | +/** @var \Psr\Http\Message\ResponseInterface $response */ |
| 68 | +$response = $errorHandler->process($request, $handler); |
| 69 | +``` |
0 commit comments