PHPackages                             andrewdyer/shutdown-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. andrewdyer/shutdown-handler

ActiveLibrary[HTTP &amp; Networking](/categories/http)

andrewdyer/shutdown-handler
===========================

A Slim library for converting fatal errors into HTTP responses using configurable responders and emitters

0.1.3(3w ago)081MITPHPPHP ^8.3CI passing

Since Apr 7Pushed 3w agoCompare

[ Source](https://github.com/andrewdyer/shutdown-handler)[ Packagist](https://packagist.org/packages/andrewdyer/shutdown-handler)[ Docs](https://github.com/andrewdyer/shutdown-handler)[ RSS](/packages/andrewdyer-shutdown-handler/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (4)Dependencies (10)Versions (4)Used By (0)

Shutdown Handler
================

[](#shutdown-handler)

A Slim library for converting fatal errors into HTTP responses using configurable responders and emitters.

[![Latest Stable Version](https://camo.githubusercontent.com/bcfafe3891aac9bf157fb406f70829e8c4152e171b9d6ca6c43aafcc8adb2df0/687474703a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f763f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewdyer/shutdown-handler)[![Total Downloads](https://camo.githubusercontent.com/40c2281935540c394b58b3d5440ddaf2101edd70f79970d95ac6aa758b919c40/687474703a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f646f776e6c6f6164733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewdyer/shutdown-handler)[![License](https://camo.githubusercontent.com/5051ed466b865957331ec3fa2dbe7c76bc47a8a7dfa166d7729e40489aaed4f7/687474703a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f6c6963656e73653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewdyer/shutdown-handler)[![PHP Version Require](https://camo.githubusercontent.com/f1842b58402fb698cf82582caf0de27ffa224025a42d88cb282a5d0306210f18/687474703a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f726571756972652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrewdyer/shutdown-handler)

Introduction
------------

[](#introduction)

This library provides a shutdown handler for [Slim Framework](https://www.slimframework.com/) applications by intercepting fatal errors and converting them into consistent HTTP responses using configurable responder and emitter strategies. The handler is fully composable, supports multiple implementations, and integrates with existing Slim error handling and response emission workflows.

Prerequisites
-------------

[](#prerequisites)

- **[PHP](https://www.php.net/)**: Version 8.3 or higher is required.
- **[Composer](https://getcomposer.org/)**: Dependency management tool for PHP.
- **[Slim Framework](https://www.slimframework.com/)**: Version 4 is required.

Installation
------------

[](#installation)

```
composer require andrewdyer/shutdown-handler
```

Getting Started
---------------

[](#getting-started)

An error responder and response emitter are required before registering the shutdown handler.

### 1. Create an error responder

[](#1-create-an-error-responder)

Error responders define how errors are transformed into HTTP responses.

```
use AndrewDyer\ShutdownHandler\Contracts\ErrorResponderInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;

final class MyErrorResponder implements ErrorResponderInterface
{
    public function createResponse(
        ServerRequestInterface $request,
        Throwable $exception,
        bool $displayErrorDetails
    ): ResponseInterface {
        // Custom response logic
    }
}
```

Alternatively, wrap existing logic using `CallableErrorResponder`:

```
use AndrewDyer\ShutdownHandler\Adapters\CallableErrorResponder;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;

$errorResponder = new CallableErrorResponder(
    static fn (
        ServerRequestInterface $request,
        Throwable $exception,
        bool $displayErrorDetails
    ): ResponseInterface => $httpErrorHandler(
        $request,
        $exception,
        $displayErrorDetails,
        false,
        false
    )
);
```

The callable must accept a request, exception, and display flag, and return a PSR-7 response.

### 2. Create a response emitter

[](#2-create-a-response-emitter)

Response emitters are responsible for sending responses to the client.

```
use AndrewDyer\ShutdownHandler\Contracts\ResponseEmitterInterface;
use Psr\Http\Message\ResponseInterface;

final class MyResponseEmitter implements ResponseEmitterInterface
{
    public function emit(ResponseInterface $response): void
    {
        // Custom emit logic
    }
}
```

Alternatively, wrap an existing emitter using `CallableResponseEmitter`:

```
use AndrewDyer\ShutdownHandler\Adapters\CallableResponseEmitter;
use Psr\Http\Message\ResponseInterface;

$responseEmitter = new CallableResponseEmitter(
    static fn (ResponseInterface $response): void => $slimEmitter->emit($response)
);
```

The adapter wraps an existing emitter implementation.

Usage
-----

[](#usage)

Register the shutdown handler to convert fatal errors into consistent HTTP responses:

```
use AndrewDyer\ShutdownHandler\ShutdownHandler;

$shutdownHandler = new ShutdownHandler(
    $request,
    $errorResponder,
    $responseEmitter,
    $displayErrorDetails
);

register_shutdown_function($shutdownHandler);
```

The `$errorResponder` and `$responseEmitter` values can come from custom implementations or the callable adapters shown in Getting Started.

License
-------

[](#license)

Licensed under the [MIT license](https://opensource.org/licenses/MIT) and is free for private or commercial projects.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance95

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~28 days

Total

3

Last Release

22d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/666597ea6e46748a89fe8764d1a45b4d0da97daf1bb1e9770ea34ae41f706d08?d=identicon)[andrewdyer](/maintainers/andrewdyer)

---

Top Contributors

[![andrewdyer](https://avatars.githubusercontent.com/u/8114523?v=4)](https://github.com/andrewdyer "andrewdyer (15 commits)")

---

Tags

error-handlingphppsr-7shutdownslimpsr-7phpslimerror handlingshutdown

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/andrewdyer-shutdown-handler/health.svg)

```
[![Health](https://phpackages.com/badges/andrewdyer-shutdown-handler/health.svg)](https://phpackages.com/packages/andrewdyer-shutdown-handler)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.8k](/packages/guzzlehttp-psr7)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28146.3k](/packages/phpro-http-tools)[genkgo/archive-stream

Stream a ZIP file (memory efficient) as a PSR-7 message

3064.2k](/packages/genkgo-archive-stream)[tkhamez/slim-role-auth

Role-based authorization for the Slim framework

1410.4k](/packages/tkhamez-slim-role-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
