PHPackages                             adagio/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. adagio/middleware

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

adagio/middleware
=================

0.1.0(9y ago)2341PHPCI failing

Since Mar 16Pushed 9y ago1 watchersCompare

[ Source](https://github.com/kevengodet/middleware)[ Packagist](https://packagist.org/packages/adagio/middleware)[ RSS](/packages/adagio-middleware/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

adagio/middleware
=================

[](#adagiomiddleware)

[![Latest Stable Version](https://camo.githubusercontent.com/13b7c3a625b591de2a4d30c8b26d06534d72dc86eda0c6df6b071a10340b582d/68747470733a2f2f706f7365722e707567782e6f72672f61646167696f2f6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/adagio/middleware)[![Build Status](https://camo.githubusercontent.com/2c09a07c8c5a8c602d909eee8e14915dfe599292710fc1caddade467356aedc0/68747470733a2f2f7472617669732d63692e6f72672f61646167696f6c6162732f6d6964646c65776172652e737667)](https://travis-ci.org/adagiolabs/middleware)[![License](https://camo.githubusercontent.com/3fa211605d39a2882613f7658d63440388fdcabccf100dd79ef7a6cb7990eb71/68747470733a2f2f706f7365722e707567782e6f72672f61646167696f2f6d6964646c65776172652f6c6963656e7365)](https://packagist.org/packages/adagio/middleware)[![Total Downloads](https://camo.githubusercontent.com/a49b637432b20de2abc432c9a7fe5db6c3aaf13bc68a1e5472ae5821f5adda10/68747470733a2f2f706f7365722e707567782e6f72672f61646167696f2f6d6964646c65776172652f646f776e6c6f616473)](https://packagist.org/packages/adagio/middleware)

[`adagio/middleware`](https://github.com/adagiolabs/middleware) library allows to implement middlewares with various data types easily.

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

[](#installation)

Install [Composer](https://getcomposer.org) and run the following command to get the latest version:

```
composer require adagio/middleware
```

Quick start
-----------

[](#quick-start)

todo.

Middlewares principles
----------------------

[](#middlewares-principles)

- A middleware signature MUST include the input data, the output data to hydrate and the next middleware to call.
- A middleware MUST return a valid output data.
- A middle ware CAN process data before or after calling the next midleware.
- The very last middleware "hidden in the stack" just returns the output data.

Transition to middlewares
-------------------------

[](#transition-to-middlewares)

Imagine you want to add a middleware pipeline to an existing image-editing library.

Here is the way you can do it without middlewares:

```
// I want to solarize, rotate, unblur and then sepia my image (parameters are
// voluntarily omitted for clarity).
$image = (new SepiaFilter)
    ->filter((new UnblurFilter)
    ->filter((new RotateFilter)
    ->filter((new SolarizedFilter)
    ->filter(new Image('/path/to/image')))));
```

Problems are:

- you have to declare the pipeline backward
- big parenthesis mess
- you cannot declare a pipeline to use on other images later

With [`adagio/middleware`](https://github.com/adagiolabs/middleware), you can do it easily:

```
use Adagio\Middleware\Stack;

$pipe = new Stack([
    new SolarizedFilter,
    new RotateFilter,
    new UnblurFilter,
    new SepiaFilter,
]);

$image = $stack(new Image('/path/to/image'));
```

Filters have just to respect the following signature convention:

```
function (Image $image, callable $next): Image
{
    // Maybe do something with $image

    $resultingImage = $next($image);

    // Maybe do something with $resultingImage

    return $resultingImage;
}
```

Each filter must pass the `$image` to the `$next` element of the pipe and can modify it before of after passing it.

Filters can be any callable respecting the given signature.

More complex example: DB query processing
-----------------------------------------

[](#more-complex-example-db-query-processing)

Middlewares are even more useful when the given and the returned objects are different. Think about a SQL query processor with the following signature:

```
function (SqlQuery $query, ResultSet $resultSet, callable $next): ResultSet
```

You can then provide a caching middleware:

```
final class QueryCache
{
    // ...

    public function __invoke(SqlQuery $query, ResultSet $resultSet, callable $next): ResultSet
    {
        // If the query is already in cache, return the ResultSet and don't
        // trigger the rest of the middleware stack
        if ($this->resultSetCache->hasQuery($query)) {
            return $this->resultSetCache->getFromQuery($query);
        }

        $finalResultSet = $next($query, $resultSet);

        $this->resultSetCache->add($query, $finalResultSet);

        return $finalResultSet;
    }
}
```

You can also provide a middleware that translates from a SQL standard to another, a SQL validator, a client-side cluster/shard solution, a logger, a performance monitor, ...

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

3394d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/73ceff9db3962fd4eb700296f37b1e863c8c657fe5941d8d91dc7c8e9023f8bc?d=identicon)[Keven](/maintainers/Keven)

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[xxh/think-wxminihelper

weixin mini program helper

1561.2k](/packages/xxh-think-wxminihelper)[bigperson/laravel-exchange1c

Catalog Loader from 1c - CommerceML with laravel

333.3k](/packages/bigperson-laravel-exchange1c)

PHPackages © 2026

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