PHPackages                             gpslab/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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. gpslab/middleware

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

gpslab/middleware
=================

TInfrastructure for use middleware in applications

v1.1.0(8y ago)841MITPHPPHP &gt;=5.5.0

Since Jun 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/gpslab/middleware)[ Packagist](https://packagist.org/packages/gpslab/middleware)[ Docs](https://github.com/gpslab/middleware)[ RSS](/packages/gpslab-middleware/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (4)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/197ce10de8ce8eb256a26eedfd5d0712f700b091c24fec1417cdcbfa45f39baf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6770736c61622f6d6964646c65776172652e7376673f6d61784167653d33363030266c6162656c3d737461626c65)](https://packagist.org/packages/gpslab/middleware)[![Total Downloads](https://camo.githubusercontent.com/21aa5410bfef4aa1a07c79ad6e077376b0510aea4e230296e639ddd79d13ad1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6770736c61622f6d6964646c65776172652e7376673f6d61784167653d33363030)](https://packagist.org/packages/gpslab/middleware)[![Build Status](https://camo.githubusercontent.com/78a2dd57438ad361d453bfcddbaf1806a1f7601139b3559564b9dde437004682/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6770736c61622f6d6964646c65776172652e7376673f6d61784167653d33363030)](https://travis-ci.org/gpslab/middleware)[![Coverage Status](https://camo.githubusercontent.com/e938df99a22f3888371d91077624beb8ad04cba1f7a44358756010a0b5582bcf/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6770736c61622f6d6964646c65776172652e7376673f6d61784167653d33363030)](https://coveralls.io/github/gpslab/middleware?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/dd58b29adaef4a60b6fd03f6603ae0f208782c3966618703a9765267ec2eca8e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6770736c61622f6d6964646c65776172652e7376673f6d61784167653d33363030)](https://scrutinizer-ci.com/g/gpslab/middleware/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/a699b48fea1fc7b1b7acfdfc44e7ce2364737de62d812c827970d2f59dae1f61/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f65643931313565302d323833662d343739392d393933632d3337373761303434313134642e7376673f6d61784167653d33363030266c6162656c3d534c496e7369676874)](https://insight.sensiolabs.com/projects/ed9115e0-283f-4799-993c-3777a044114d)[![StyleCI](https://camo.githubusercontent.com/e81f1a0d0188788c0296ea4426fd6ed6924f579eb1750b341dc9435a148449cc/68747470733a2f2f7374796c6563692e696f2f7265706f732f39323331323638302f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/92312680)[![License](https://camo.githubusercontent.com/89006485673a8c14bc85ee35085b8961d0baadc151dc1f35ffd06f5f988f589e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6770736c61622f6d6964646c65776172652e7376673f6d61784167653d33363030)](https://github.com/gpslab/middleware)

Infrastructure for use middleware in applications
=================================================

[](#infrastructure-for-use-middleware-in-applications)

[![Request delegate pipeline](request-delegate-pipeline.png)](request-delegate-pipeline.png)

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

[](#installation)

Pretty simple with [Composer](http://packagist.org), run:

```
composer require gpslab/middleware
```

Middleware chain
----------------

[](#middleware-chain)

`MiddlewareChain` contains a middlewares (`Middleware`) and sequentially apply them to the message by chain.

There are 3 implementations of the chain, but you can make your own.

- `DirectBindingMiddlewareChain` - direct binding;
- `ContainerMiddlewareChain` - [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md) container;
- `SymfonyContainerMiddlewareChain` - Symfony container *(Symfony 3.3 [implements](http://symfony.com/blog/new-in-symfony-3-3-psr-11-containers) a [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*.

Handle command (CQRS)
---------------------

[](#handle-command-cqrs)

Example usage middleware for handle Commands in [CQRS](https://github.com/gpslab/cqrs).

```
// middleware chain
$chain = new DirectBindingMiddlewareChain();

// add logger middleware
$chain->append(new LoggerMiddleware($logger));
// add validator middleware
$chain->append(new ValidatorMiddleware($validator));
// add middleware for handle command from origin command bus
$chain->append(new CommandMiddleware($command_bus));

// configure command bus
$bus = new MiddlewareCommandBus($chain);

// handle command
try {
    $bus->handle($my_command);
} catch(InvalidMessageException $e) {
    // show validation errors
    var_dump($e->getMessages());
}
```

Handle query (CQRS)
-------------------

[](#handle-query-cqrs)

Example usage middleware for handle Queries in [CQRS](https://github.com/gpslab/cqrs).

```
// middleware chain
$chain = new DirectBindingMiddlewareChain();

// add logger middleware
$chain->append(new LoggerMiddleware($logger));
// add validator middleware
$chain->append(new ValidatorMiddleware($validator));
// add middleware for handle query from origin query bus
$chain->append(new QueryMiddleware($query_bus));

// configure query bus
$bus = new MiddlewareQueryBus($chain);

// handle query
try {
    $bus->handle($my_query);
} catch (InvalidMessageException $e) {
    // show validation errors
    var_dump($e->getMessages());
}
```

Handle Domain event
-------------------

[](#handle-domain-event)

Example usage middleware for handle [domain events](https://github.com/gpslab/domain-event).

```
// middleware chain
$chain = new DirectBindingMiddlewareChain();

// add logger middleware
$chain->append(new LoggerMiddleware($logger));
// add middleware for handle event from origin domain event bus
$chain->append(new DomainEventMiddleware($domain_event_bus));

// configure domain event bus
$bus = new MiddlewareDomainEventBus($chain);

// publish domain event
$bus->publish($my_event);
```

License
-------

[](#license)

This bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~12 days

Total

3

Last Release

3217d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a6415c83577efe7b70d9ae4a3bb12958adc11c16e530ff844ff217b0fd0c54a?d=identicon)[Peter Gribanov](/maintainers/Peter%20Gribanov)

---

Top Contributors

[![peter-gribanov](https://avatars.githubusercontent.com/u/1954436?v=4)](https://github.com/peter-gribanov "peter-gribanov (41 commits)")

---

Tags

cqrsdomain-eventinfrastructuremiddlewarephppsr-11psr-3symfonypsr-3middlewaresymfonyPSR-11cqrsinfrastructure

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[bugsnag/bugsnag-symfony

Official BugSnag notifier for Symfony applications.

453.0M3](/packages/bugsnag-bugsnag-symfony)[chubbyphp/chubbyphp-framework

A minimal, highly performant middleware PSR-15 microframework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use.

13544.4k4](/packages/chubbyphp-chubbyphp-framework)[authbucket/oauth2-symfony-bundle

Symfony OAuth2Bundle

839.2k1](/packages/authbucket-oauth2-symfony-bundle)[bref/logger

All you need to log with Bref on AWS Lambda

331.5M8](/packages/bref-logger)[devthis/console-logg

Effortless artisan console output with your usual Laravel logger

1112.7k](/packages/devthis-console-logg)

PHPackages © 2026

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