PHPackages                             ajgarlag/psr15-dispatcher - 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. [Framework](/categories/framework)
4. /
5. ajgarlag/psr15-dispatcher

ActiveProject[Framework](/categories/framework)

ajgarlag/psr15-dispatcher
=========================

Component to dispatch PSR-15 middlewares

0.4.3(2y ago)94.5k2[1 PRs](https://github.com/ajgarlag/psr15-dispatcher/pulls)MITPHPPHP &gt;=8.0

Since Jan 13Pushed 2y ago2 watchersCompare

[ Source](https://github.com/ajgarlag/psr15-dispatcher)[ Packagist](https://packagist.org/packages/ajgarlag/psr15-dispatcher)[ RSS](/packages/ajgarlag-psr15-dispatcher/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (8)Versions (11)Used By (0)

Psr15 Dispatcher
================

[](#psr15-dispatcher)

The Psr15 Dispatcher component allows you to dispatch [PSR-15](https://www.php-fig.org/psr/psr-15/) middlewares.

[![Build Status](https://github.com/ajgarlag/psr15-dispatcher/actions/workflows/tests.yaml/badge.svg?branch=master)](https://github.com/ajgarlag/psr15-dispatcher/actions/workflows/tests.yaml)[![Latest Stable Version](https://camo.githubusercontent.com/1fdb70b921e02f4576c1d3d4082492635ab8843dcb908ce8ad14f35dca5dda76/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d646973706174636865722f762f737461626c652e706e67)](https://packagist.org/packages/ajgarlag/psr15-dispatcher)[![Latest Unstable Version](https://camo.githubusercontent.com/01c466b0b642a3d5d59d476b0d8057dd938a7647284a65116a3282da3cbffc71/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d646973706174636865722f762f756e737461626c652e706e67)](https://packagist.org/packages/ajgarlag/psr15-dispatcher)[![Total Downloads](https://camo.githubusercontent.com/8a13d559c4626c8f54f2e7a9eefd76829364b30f8a560e94e357c42dc3b90c22/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d646973706174636865722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/ajgarlag/psr15-dispatcher)[![Montly Downloads](https://camo.githubusercontent.com/9adb0fce8f592acef7e60c77f801a9832c2dbdf5619789c70b141f1dc6cdde7f/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d646973706174636865722f642f6d6f6e74686c792e706e67)](https://packagist.org/packages/ajgarlag/psr15-dispatcher)[![Daily Downloads](https://camo.githubusercontent.com/0ed59fe1cce99d49e4d3e9731862e160ae51c42c1f90e894d421825438dffa02/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d646973706174636865722f642f6461696c792e706e67)](https://packagist.org/packages/ajgarlag/psr15-dispatcher)[![License](https://camo.githubusercontent.com/b9eb14dd6aa37c1d8a90b75f9c4a682c4f85d78beb6ca37131638ed2f6743a6e/68747470733a2f2f706f7365722e707567782e6f72672f616a6761726c61672f70737231352d646973706174636865722f6c6963656e73652e706e67)](https://packagist.org/ajgarlag/psr15-dispatcher)

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

[](#installation)

To install the latest stable version of this component, open a console and execute the following command:

```
$ composer require ajgarlag/psr15-dispatcher

```

Usage
-----

[](#usage)

At first, you must have an app that implements [RequestHandlerInterface](https://www.php-fig.org/psr/psr-15/#21-psrhttpserverrequesthandlerinterface) or is wrapped in a `RequestHandlerInterface` implementation, that you would like to dispatch decorated with several [PSR-15](https://www.php-fig.org/psr/psr-15/) middlewares.

```
/* @var $requestHandler RequestHandlerInterface */
$requestHandler = new YourApp();
```

Now, you can choose between a `Pipe` or a `Stack` to dispatch your app.

### Pipe dispatch

[](#pipe-dispatch)

With this option, you create a `Pipe`, connect the desired middlewares and finally process the server request through the pipe, passing your app as request handler:

```
use Ajgarlag\Psr15\Dispatcher\Pipe;

$pipe = Pipe::create()
    ->withConnectedMiddleware(new FirstMiddleware())
    ->withConnectedMiddleware(new MiddleMiddleware())
    ->withConnectedMiddleware(new LastMiddleware())
;

$response = $pipe->process($request, $requestHandler);
```

The `Pipe` class implements itself the PSR-15 [MiddlewareInterface](https://www.php-fig.org/psr/psr-15/#22-psrhttpservermiddlewareinterface), so it can be connected to another `Pipe`.

#### Pipe initialization

[](#pipe-initialization)

You can pass a FIFO array of middlewares to initialize the `Pipe`:

```
$pipe = Pipe::create([
    new FirstMiddleware(),
    new MiddleMiddleware(),
    new LastMiddleware(),
]);
```

### Stack dispatch

[](#stack-dispatch)

With this option, you wrap your app request handler into an `Stack` instance, push the desired middlewares and finally process the server request through the stack. Beware that to achieve the same behavior that in the previous `Pipe` you must push middlewares in **reverse** order:

```
use Ajgarlag\Psr15\Dispatcher\Stack;

$stack = Stack::create($requestHandler)
    ->withPushedMiddleware(new LastMiddleware())
    ->withPushedMiddleware(new MiddleMiddleware())
    ->withPushedMiddleware(new FirstMiddleware())
;

$response = $stack->handle($request);
```

The `Stack` class implements itself the PSR-15 [RequestHandlerInterface](https://www.php-fig.org/psr/psr-15/#21-psrhttpserverrequesthandlerinterface), so it can be wrapped by another `Stack`.

#### Stack initialization

[](#stack-initialization)

You can pass a LIFO array of middlewares to initialize the `Stack`:

```
$stack = Stack::create($requestHandler, [
    new LastMiddleware(),
    new MiddleMiddleware(),
    new FirstMiddleware(),
]);
```

#### Pipe pushed onto the stack

[](#pipe-pushed-onto-the-stack)

My preferred option is to build a `Pipe` with middlewares connected in natural order, and then, push it onto the stack, but this is a matter of taste:

```
$stack = Stack::create($requestHandler);
$pipe = Pipe::create()
    ->withConnectedMiddleware(new FirstMiddleware())
    ->withConnectedMiddleware(new MiddleMiddleware())
    ->withConnectedMiddleware(new LastMiddleware())
;

$application = $stack->withPushedMiddleware($pipe);
```

License
-------

[](#license)

This component is under the MIT license. See the complete license in the [LICENSE](LICENSE) file.

Reporting an issue or a feature request
---------------------------------------

[](#reporting-an-issue-or-a-feature-request)

Issues and feature requests are tracked in the [Github issue tracker](https://github.com/ajgarlag/psr15-dispatcher/issues).

Author Information
------------------

[](#author-information)

Developed with ♥ by [Antonio J. García Lagar](http://aj.garcialagar.es).

If you find this component useful, please add a ★ in the [GitHub repository page](https://github.com/ajgarlag/psr15-dispatcher) and/or the [Packagist package page](https://packagist.org/packages/ajgarlag/psr15-dispatcher).

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 96.9% 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 ~345 days

Recently: every ~442 days

Total

8

Last Release

1046d ago

PHP version history (4 changes)0.1.0PHP &gt;=5.6.0

0.3.0PHP &gt;=7.0

0.4.0PHP &gt;=7.4

0.4.2PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f895b5880bdb002b96abac69a1a6630b4e20c4fbff9dbe3d47b08f0d1b7e2211?d=identicon)[ajgarlag](/maintainers/ajgarlag)

---

Top Contributors

[![ajgarlag](https://avatars.githubusercontent.com/u/388184?v=4)](https://github.com/ajgarlag "ajgarlag (31 commits)")[![tbreuss](https://avatars.githubusercontent.com/u/1334161?v=4)](https://github.com/tbreuss "tbreuss (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ajgarlag-psr15-dispatcher/health.svg)

```
[![Health](https://phpackages.com/badges/ajgarlag-psr15-dispatcher/health.svg)](https://phpackages.com/packages/ajgarlag-psr15-dispatcher)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k39](/packages/neuron-core-neuron-ai)[spiral/framework

Spiral, High-Performance PHP/Go Framework

2.1k2.2M67](/packages/spiral-framework)[cakephp/authentication

Authentication plugin for CakePHP

1214.1M106](/packages/cakephp-authentication)

PHPackages © 2026

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