Middleware to use Whoops as error handler.
This package is installable and autoloadable via Composer as middlewares/whoops.
composer require middlewares/whoops
$dispatcher = new Dispatcher([ new Middlewares\Whoops() ]); $response = $dispatcher->dispatch(new ServerRequest());
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);
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
//Do not catch errors $middleware = (new Middlewares\Whoops())->catchErrors(false);
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.
The MIT License (MIT). Please see LICENSE for more information.