middlewares / whoops
Middleware to use Whoops as error handler
Installs: 180 930
Dependents: 31
Suggesters: 1
Security: 0
Stars: 32
Watchers: 2
Forks: 7
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- filp/whoops: ^2.5
- middlewares/utils: ^3.0 || ^4.0
- psr/container: ^1.0 || ^2.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- eloquent/phony-phpunit: ^5.0 || ^7.0
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.2
- oscarotero/php-cs-fixer-config: ^1.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8|^9
- squizlabs/php_codesniffer: ^3.0
README
Middleware to use Whoops as error handler.
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/whoops.
composer require middlewares/whoops
Example
$dispatcher = new Dispatcher([ new Middlewares\Whoops() ]); $response = $dispatcher->dispatch(new ServerRequest());
Usage
The constructor accepts a Whoops\Run
instance but creates one automatically if it's not provided. Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface
as the second argument to create the response. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.
$whoops = new Whoops\Run(); $responseFactory = new MyOwnResponseFactory(); //Create a Run instance automatically $middleware = new Middlewares\Whoops(); //Pass your own Run instance $middleware = new Middlewares\Whoops($whoops); //Pass a Run instance and ResponseFactory $middleware = new Middlewares\Whoops($whoops, $responseFactory);
catchErrors
To catch not only throwable exceptions, but also php errors. This makes whoops to be registered temporary in order to capture the errors using set_error_handler
. It's enabled by default so, to disable it you have to use ->catchErrors(false)
;
//Do not catch errors $middleware = (new Middlewares\Whoops())->catchErrors(false);
handlerContainer
This option allows to define a custom PSR-11 container used to create the intance of Whoops\Handler\HandlerInterface
based in the Accept
header in the request.
Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.