PHPackages                             phossa2/middleware - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phossa2/middleware

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

phossa2/middleware
==================

Another cool middleware runner library for PHP.

2.0.1(9y ago)113.4k1MITPHPPHP ~5.4|~7.0

Since Sep 24Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phossa2/middleware)[ Packagist](https://packagist.org/packages/phossa2/middleware)[ Docs](https://github.com/phossa2/middleware)[ RSS](/packages/phossa2-middleware/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (6)Versions (3)Used By (1)

phossa2/middleware \[ABANDONED\]
================================

[](#phossa2middleware-abandoned)

**PLEASE USE [phoole/middleware](https://github.com/phoole/middleware) library instead**

[![Build Status](https://camo.githubusercontent.com/2caba56fe007221d944ace4f774fb93aa094e1560cebd50dba6bb2d6fdf6a6bf/68747470733a2f2f7472617669732d63692e6f72672f70686f737361322f6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa2/middleware)[![Code Quality](https://camo.githubusercontent.com/c1476127fdb9f43dd066acaef72ea6ea30c273ddf9a01b3e3f84b6db3d6454ad/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70686f737361322f6d6964646c65776172652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phossa2/middleware/)[![Code Climate](https://camo.githubusercontent.com/cae45fa13da1ce31a779bc4ea1c906c8298a6db3ec11e121b4446541898c82e1/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70686f737361322f6d6964646c65776172652f6261646765732f6770612e737667)](https://codeclimate.com/github/phossa2/middleware)[![PHP 7 ready](https://camo.githubusercontent.com/f63f2500dc97ac4f93063965b228bfcac62b24b07209dc6abbaaf5764ac01454/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f70686f737361322f6d6964646c65776172652f6d61737465722f62616467652e737667)](https://travis-ci.org/phossa2/middleware)[![HHVM](https://camo.githubusercontent.com/5620e72c9fc433caccd0a5293254058ca1188d0302d95918272df86018897e51/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f70686f737361322f6d6964646c65776172652e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/phossa2/middleware)[![Latest Stable Version](https://camo.githubusercontent.com/d809980feb88fe61544ac694b17fd9d7656e12fa0e068635c11a33914aa82fb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f737361322f6d6964646c65776172652e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa2/middleware)[![License](https://camo.githubusercontent.com/4fc6538ded72843e26a272d300ce4c95da083ce92576e10e4fdd505d579a8125/68747470733a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://mit-license.org/)

**phossa2/middleware** is another cool middleware runner library for PHP.

It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with [PSR-1](http://www.php-fig.org/psr/psr-1/ "PSR-1: Basic Coding Standard"), [PSR-2](http://www.php-fig.org/psr/psr-2/ "PSR-2: Coding Style Guide"), [PSR-3](http://www.php-fig.org/psr/psr-3/ "PSR-3: Logger Interface"), [PSR-4](http://www.php-fig.org/psr/psr-4/ "PSR-4: Autoloader"), [PSR-7](http://www.php-fig.org/psr/psr-7/ "PSR-7: HTTP Message Interfaces") and the proposed [PSR-5](https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md "PSR-5: PHPDoc")

Why another middleware runner ?
-------------------------------

[](#why-another-middleware-runner-)

- It was started to be a [PSR-15](https://github.com/php-fig/fig-standards/tree/master/proposed/http-middleware)compatible middleware runner. But we don't like the single-pass approach of PSR-15. So it turns out to be a double-pass and PSR-15ish library.
- Adopted nice feature of [`condition`](#condition) from [woohoolabs/harmony](https://github.com/woohoolabs/harmony). But we don't agree its tight-binding with dispatcher.
- A couple of cool [features](#features) unique to this library.

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

[](#installation)

Install via the `composer` utility.

```
composer require "phossa2/middleware"
```

or add the following lines to your `composer.json`

```
{
    "require": {
       "phossa2/middleware": "2.*"
    }
}
```

Features
--------------------------------------------

[](#features)

- Able to [use](#comp) most of the double-pass middlewares out there.
- Able to use a middleware [queue](#queue) (a group of middlewares) as a generic middleware in another(or the main) queue.
- Able to conditionally execute a middleware or a sub queue base on a [condition](#condition).
- Able to [branching](#branch) into a subqueue and terminate when the subqueue finishes.

Usage
-----

[](#usage)

Create the middleware queue, then process all the middlewares.

```
use Phossa2\Middleware\Queue;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;

// create middleware queue
$mws = new Queue([
    new LoggerMiddleware(),
    new DispatcherMiddleware()
]);

// process the queue
$response = $mws->process(ServerRequestFactory::fromGlobals(), new Response());
```

Or push middlewares to the queue after its instantiation,

```
$mws = (new Queue())
    ->push(new LoggerMiddleware())
    ->push(new DispatcherMiddleware());
```

Advanced
--------

[](#advanced)

- Compatibility with PSR-7 middlewares.

    PSR-7 double-pass middleware with the following signature is supported,

    ```
    use Psr\Http\Message\RequestInterface;
    use Psr\Http\Message\ResponseInterface;

    function (
        RequestInterface $request,
        ResponseInterface $response,
        callable $next
    ) : ResponseInterface {
        // ...
    }
    ```

    Lots of middlewares out there then can be used without modification, such as [psr7-middlewares](https://github.com/oscarotero/psr7-middlewares).
- Subqueue

    `Phossa2\Middleware\Queue` implements the `Phossa2\Middleware\Interfaces\MiddlewareInterface`, so the queue itself can be used as a generic middleware.

    ```
    // subqueue
    $subQueue = new Queue([
        new ResponseTimeMiddleware(),
        new LoggingMiddleware(),
        // ...
    ]);

    // main middleware queue
    $mws = new Queue([
        $subQueue,
        new DispatcherMiddleware(),
        // ...
    ]);

    $response = $mws->process(ServerRequestFactory::fromGlobals(), new Response());
    ```
- Use of conditions

    A `condition` is a callable with the signature of,

    ```
    function (RequestInterface $request, ResponseInterface $response) : bool
    {
        // ...
    }
    ```

    Or an instanceof `Phossa2\Middleware\Interfaces\ConditionInterface`.

    A condition can be attached to a middleware or a subqueue. And the middleware will be executed only if the condition is evaluated to `TRUE`.

    ```
    // add condition during instantiation
    $mws = new Queue([
        [$subQueue, new DebugTurnedOnCondition()],
        new DispatcherMiddleware(),
    ]);

    // or during the push
    $mws->push(new AuthMiddleware(), new PathPrefixCondition('/user'));
    ```
- Subqueue termination - branching

    Sometimes, user wants the whole middleware processing terminate right after a subqueue finishes instead of continue processing the parent queue.

    ```
    // use terminatable queue
    $tQueue = new TerminateQueue([...]);

    $mws = new Queue([
        [$tQueue, new SomeCondition()], // execute & terminate if condition true
        $mw2,
        $mw3,
        // ...
    ]);

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

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) from more information.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTE](CONTRIBUTE.md) for more information.

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa2/shared &gt;= 2.0.21
- A PSR-7 HTTP message implementation, such as [zend-diactoros](https://github.com/zendframework/zend-diactoros)

License
-------

[](#license)

[MIT License](http://mit-license.org/)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.5% 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 ~0 days

Total

2

Last Release

3566d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19922046?v=4)[Hong Zhang](/maintainers/phossa2)[@phossa2](https://github.com/phossa2)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (19 commits)")[![phossa2](https://avatars.githubusercontent.com/u/19922046?v=4)](https://github.com/phossa2 "phossa2 (2 commits)")

---

Tags

middlewarephossa

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phossa2-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/phossa2-middleware/health.svg)](https://phpackages.com/packages/phossa2-middleware)
```

###  Alternatives

[league/uri-components

URI components manipulation library

31937.4M89](/packages/league-uri-components)[bryanjhv/slim-session

Session middleware and helper for Slim framework 4.

233990.5k16](/packages/bryanjhv-slim-session)[timacdonald/has-parameters

A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.

228288.1k4](/packages/timacdonald-has-parameters)[reinink/remember-query-strings

Laravel middleware that automatically remembers and restores query strings.

76638.4k3](/packages/reinink-remember-query-strings)[yemenifree/laravel-arabic-numbers-middleware

auto transforms arabic/eastern to eastern/arabic numbers for i.e ١٢٣٤٥٦٧٨ to 12345678

18135.6k](/packages/yemenifree-laravel-arabic-numbers-middleware)[aldemeery/onion

A layering mechanism for PHP applications.

5812.4k3](/packages/aldemeery-onion)

PHPackages © 2026

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