middlewares / error-response
Middleware to handle responses with error status code (4xx-5xx)
Requires
- php: ^7.2 || ^8.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.3
- middlewares/utils: ^3.0
- oscarotero/php-cs-fixer-config: ^1.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8|^9
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-10-29 05:40:19 UTC
README
Middleware to format responses with HTTP error codes (4xx-5xx). Useful to create pretty 404 or 500 error pages.
Requirements
- PHP >= 7.2
- A PSR-7 http library
- A PSR-15 middleware dispatcher
Installation
This package is installable and autoloadable via Composer as middlewares/error-response.
composer require middlewares/error-response
Example
use Middlewares\ErrorResponse; Dispatcher::run([ new Middlewares\ErrorResponse() ]);
Usage
The constructor accepts an array of responders, that must implement the Middlewares\ErrorResponder\ResponderInterface
.
This package includes two basic responders: for html and json responses, that are enabled by default if no responders are passed.
//The default responders (for html and js) $responder = new Middlewares\ErrorResponse(); //Use your custom responders $responder = new Middlewares\ErrorResponse([ new MyHtmlResponder(), new MyJsonResponder() ]);
Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.