PSR-15 middleware to use Whoops as error handler

Last update: May 3, 2022

middlewares/whoops

Latest Version on Packagist Software License Testing Total Downloads

Middleware to use Whoops as error handler.

Requirements

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.

GitHub

https://github.com/middlewares/whoops
You might also like...

It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications

It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications

OpenAPI PSR-7 Message (HTTP Request/Response) Validator This package can validate PSR-7 messages against OpenAPI (3.0.x) specifications expressed in Y

May 20, 2022

Tukio is a complete and robust implementation of the PSR-14 Event Dispatcher specification

Tukio is a complete and robust implementation of the PSR-14 Event Dispatcher specification. It supports normal and debug Event Dispatchers, both runtime and compiled Providers, complex ordering of Listeners, and attribute-based registration on PHP 8.

May 19, 2022

A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax.

Slack for PHP | A simple PHP package for sending messages to Slack with incoming webhooks, focused on ease-of-use and elegant syntax. supports: PHP 7.

May 15, 2022

Quickly and easily expose Doctrine entities as REST resource endpoints with the use of simple configuration with annotations, yaml, json or a PHP array.

Drest Dress up doctrine entities and expose them as REST resources This library allows you to quickly annotate your doctrine entities into restful res

Jan 27, 2022

An easy to use Fractal wrapper built for Laravel and Lumen applications

An easy to use Fractal wrapper built for Laravel and Lumen applications

An easy to use Fractal wrapper built for Laravel and Lumen applications The package provides a nice and easy wrapper around Fractal for use in your La

May 20, 2022

An Unleash bundle for Symfony applications to provide an easy way to use feature flags

Unleash Bundle An Unleash bundle for Symfony applications. This provide an easy way to implement feature flags using Gitlab Feature Flags Feature. Ins

Feb 2, 2022

A PHP library for the CoinMarketCap API designed to be easy to use.

Help wanted: I don't have enough time to keep updating this library, if you can, don't be shy. Pull requests are welcome. PHP CoinMarketCap API This p

Apr 15, 2022

This small POC aims to show how Symfony is able, natively without modifications, to use subdirectories for Entities, Repositories, controllers, views…

POC - Using Sub Directories in a Symfony Project This small POC aims to show how Symfony is able, natively without modifications, to use subdirectorie

May 12, 2022

GraPHPinator ⚡ 🌐 ⚡ Easy-to-use & Fast GraphQL server implementation for PHP

Easy-to-use & Fast GraphQL server implementation for modern PHP. Includes features from latest draft, middleware directives and modules with extra functionality.

Apr 27, 2022
Comments
  • 1. Allow a default handler to be used

    I want to take advantage of the content type guessing this library does, while at the same time specifying which editor the PrettyPageHandler should use.

    This PR allows this behaviour by supporting a default handler to be used if no content specific one is in use

    Reviewed by duncan3dc at 2018-05-20 18:37
  • 2. Fatal errors result in an empty 500 response

    With this middleware enabled any E_ERROR that is triggered during inner middleware execution will result in a HTTP 500 with an empty body.

    This is because Whoops uses an output buffer to render fatal errors as part of the shutdown handler, and this middleware throws away the output buffer that contains the error message.

    I tried numerous things to work around this but couldn't come up with a good way to do it in PHP <7.0. I don't really expect this issue to be resolved but I did want it documented.

    Reviewed by shadowhand at 2017-06-20 20:12
  • 3. Support PHP 8

    Tests almost pass, there is one problem with the test itself:

    $this->assertNotFalse(strpos((string) $response->getBody(), 'Undefined variable: b'));
    

    The message has changed and now contains dollar sign: PHP Warning: Undefined variable $b

    Obvious blocker as I understand: https://github.com/middlewares/utils/issues/22

    Reviewed by arokettu at 2020-11-24 23:37
PSR-7 middleware foundation for building and dispatching middleware pipelines

laminas-stratigility From "Strata", Latin for "layer", and "agility". This package supersedes and replaces phly/conduit. Stratigility is a port of Sen

May 1, 2022
Disable Google's FLoC with help of PSR-15 middleware

Disable Google's FLoC with PSR-15 middleware This package will help you disable Google's FLoC. Installation You can install the package via composer:

Apr 1, 2022
PSR-15 middleware to geolocate the client using the ip address

middlewares/geolocation ![SensioLabs Insight][ico-sensiolabs] Middleware to geolocate the client using the ip address and Geocoder and save the result

Mar 22, 2022
A PSR-15 middleware adapter for react/http

A PSR-15 middleware adapter for react/http Wraps PSR-15 middleware into coroutines using RecoilPHP making them usable within react/http as middleware.

Feb 12, 2022
Use middleware to decorate method calls within your application code.
Use middleware to decorate method calls within your application code.

Laravel Middlewarize ?? Chain of Responsibility Design Pattern In Laravel Apps ?? You can use middlewares to decorate any method calls on any object.

May 9, 2022
Provides a Middleware to integration Tideways into Symfony Messenger Processing

Tideways Middleware for Symfony Messenger This package is currently under development and might be moved into the Tideways PHP Extension or stay indep

Jan 25, 2022
A lightweight middleware to make api routing session capable.

Laravel stateless session A lightweight middleware to make api routing session capable. Installing $ composer require overtrue/laravel-stateless-sessi

Nov 30, 2021
A based PSR-15 microframework that also sets maximum flexibility with minimum complexity and easy replaceability of the individual components, but also of the framework.
A based PSR-15 microframework that also sets maximum flexibility with minimum complexity and easy replaceability of the individual components, but also of the framework.

chubbyphp-framework Description A based PSR-15 microframework that also sets maximum flexibility with minimum complexity and easy replaceability of th

Apr 10, 2022
The efficient and elegant, PSR-7 compliant JSON:API 1.1 client library for PHP

Woohoo Labs. Yang Woohoo Labs. Yang is a PHP framework which helps you to communicate with JSON:API servers more easily. Table of Contents Introductio

May 5, 2022
OpenAPI(v3) Validators for Symfony http-foundation, using `league/openapi-psr7-validator` and `symfony/psr-http-message-bridge`.

openapi-http-foundation-validator OpenAPI(v3) Validators for Symfony http-foundation, using league/openapi-psr7-validator and symfony/psr-http-message

Nov 19, 2021