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 shutdown handler for Slim Framework applications that converts fatal errors into consistent HTTP responses through pluggable responder and emitter strategies

0.1.0(1mo ago)011↓100%MITPHPPHP ^8.3CI passing

Since Apr 7Pushed 1mo agoCompare

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

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

[![Shutdown Handler](https://camo.githubusercontent.com/1cf16388a2c41615f2e4d9626f585f03f986ba7cdeef922736b1db13ab825f1e/68747470733a2f2f7075626c69632d6173736574732e616e64726577647965722e726f636b732f696d616765732f636f766572732f73687574646f776e2d68616e646c65722e706e67)](https://camo.githubusercontent.com/1cf16388a2c41615f2e4d9626f585f03f986ba7cdeef922736b1db13ab825f1e/68747470733a2f2f7075626c69632d6173736574732e616e64726577647965722e726f636b732f696d616765732f636f766572732f73687574646f776e2d68616e646c65722e706e67)

 [![Latest Stable Version](https://camo.githubusercontent.com/ca56c2ef7976080abb74c25689acec64a20b6b6728a62c825648c9aad143eb2d/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f762f737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/andrewdyer/shutdown-handler) [![Total Downloads](https://camo.githubusercontent.com/85813a3a3f2ebf5aed5f07b989b5ad6196c699c8695e2084fe5dd8615ec8abb4/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f646f776e6c6f6164733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/andrewdyer/shutdown-handler) [![License](https://camo.githubusercontent.com/dde7100ecdb0270eeb88921af9db2299d894396e83cb4da1d3b49afd388891b4/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/andrewdyer/shutdown-handler) [![PHP Version Required](https://camo.githubusercontent.com/82a0544613193c855de337dbab5cf8c9d45b6564f79c674ea979edb0f9bb4cfd/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f73687574646f776e2d68616e646c65722f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/andrewdyer/shutdown-handler)

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

[](#shutdown-handler)

A shutdown handler for [Slim Framework](https://www.slimframework.com/) applications that converts fatal errors into consistent HTTP responses through pluggable responder and emitter strategies.

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

[](#introduction)

This library provides a shutdown handler for Slim applications. It intercepts fatal errors and transforms them into consistent HTTP responses, maintaining predictable application behaviour. The handler is fully composable, allowing different responder and emitter implementations to be combined as required, and integrates seamlessly 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

38

—

LowBetter than 85% of packages

Maintenance94

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

33d 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 (8 commits)")

---

Tags

psr-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

[genkgo/archive-stream

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

3063.0k](/packages/genkgo-archive-stream)[maurobonfietti/rest-api-slim-php

Example of REST API with Slim PHP Framework.

3061.7k](/packages/maurobonfietti-rest-api-slim-php)[maurobonfietti/slim4-api-skeleton

Useful skeleton for RESTful API development, using PHP and Slim 4.

1392.3k](/packages/maurobonfietti-slim4-api-skeleton)[tkhamez/slim-role-auth

Role-based authorization for the Slim framework

1410.2k](/packages/tkhamez-slim-role-auth)[httpsoft/http-basis

Simple and fast HTTP microframework implementing PSR standards

1334.9k1](/packages/httpsoft-http-basis)

PHPackages © 2026

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