Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/middlewares/whoops
PSR-15 middleware to use Whoops as error handler
https://github.com/middlewares/whoops
error-handling http middleware psr-15 whoops
Last synced: about 1 month ago
JSON representation
PSR-15 middleware to use Whoops as error handler
- Host: GitHub
- URL: https://github.com/middlewares/whoops
- Owner: middlewares
- License: mit
- Created: 2016-10-02T10:25:40.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-21T14:45:50.000Z (9 months ago)
- Last Synced: 2024-04-25T18:21:08.172Z (8 months ago)
- Topics: error-handling, http, middleware, psr-15, whoops
- Language: PHP
- Homepage:
- Size: 53.7 KB
- Stars: 32
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-psr15-middlewares - middlewares/whoops - Use [Whoops](https://github.com/filp/whoops) as error handler. (Packages / Development)
README
# middlewares/whoops
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE)
![Testing][ico-ga]
[![Total Downloads][ico-downloads]][link-downloads]Middleware to use [Whoops](https://github.com/filp/whoops) as error handler.
## Requirements
* PHP >= 7.2
* A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)## Installation
This package is installable and autoloadable via Composer as [middlewares/whoops](https://packagist.org/packages/middlewares/whoops).
```sh
composer require middlewares/whoops
```## Example
```php
$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](https://github.com/middlewares/utils#factory) will be used to detect it automatically.
```php
$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)`;
```php
//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](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.
The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.
[ico-version]: https://img.shields.io/packagist/v/middlewares/whoops.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-ga]: https://github.com/middlewares/whoops/workflows/testing/badge.svg
[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/whoops.svg?style=flat-square[link-packagist]: https://packagist.org/packages/middlewares/whoops
[link-downloads]: https://packagist.org/packages/middlewares/whoops