PHPackages                             websoftwares/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. [HTTP &amp; Networking](/categories/http)
4. /
5. websoftwares/middleware

ActiveLibrary[HTTP &amp; Networking](/categories/http)

websoftwares/middleware
=======================

This package lets u manage middleware for HTTP a request and response that implement the PSR-7 HTTP message interfaces.

0.0.11(11y ago)231MITPHPPHP &gt;=5.5.0

Since May 1Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (6)Versions (5)Used By (0)

\#Middleware (v0.0.\*) This package lets u manage middleware for a HTTP request and response that implement the [PSR-7](https://github.com/php-fig/fig-standards/blob/master/proposed/http-message.md) HTTP message interfaces `Psr\Http\Message\ServerRequestInterface` and `Psr\Http\Message\ResponseInterface`.

[![Build Status](https://camo.githubusercontent.com/2c6f24ba03c724cabe9e1d364800faf678357d249a71703acadf81c10e51a1c2/68747470733a2f2f6170692e7472617669732d63692e6f72672f776562736f667477617265732f6d6964646c65776172652e706e67)](https://travis-ci.org/websoftwares/middleware)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4691dc2f0b11f8d2cbf5c6827514ddcdb0d16e1e1e008bef2a2225f1531a1ac0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776562736f667477617265732f6d6964646c65776172652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/websoftwares/middleware/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/a0c2b4398f498395c2f148b8c3cb2def95ff113f9122bdc8dceb4798b02ad37b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776562736f667477617265732f6d6964646c65776172652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/websoftwares/middleware/?branch=master)

Installing via Composer (recommended)
-------------------------------------

[](#installing-via-composer-recommended)

Install composer in your project:

```
curl -s http://getcomposer.org/installer | php

```

Create a composer.json file in your project root:

```
{
    "require": {
		"websoftwares/middleware": ~0.0.1"
    }
}
```

Install via composer

```
php composer.phar install

```

Usage
-----

[](#usage)

Basic usage of the `MiddlewareRunner` class.

```
use Websoftwares\Middleware\MiddlewareRunner;

$middleware = new MiddlewareRunner;

// Some middleware object that is callable through invoke or a closure
// for consistency u could implement the `Websoftwares\MiddlewareInterface`.

// Invokable object
$throttleMiddleware = new ThrotteObject

// request + middelewareOne decoration foo = $request->foo + 1;
};

// response + middlewareTwo decoration bar = $response->bar . ' World';
};

$middleware->add($throttleMiddleware);
$middleware->add($middelewareOne);
$middleware->add($middlewareTwo);
...
// Add more middleware
...

$m = $middleware;

// Call
$m($request, $response);
```

Routing example with external package
-------------------------------------

[](#routing-example-with-external-package)

Their are many excellent PHP router packages and in time some will be made compatible with PSR-7. In this basic example we will show u how to use the `MiddlewareRunner` class in conjunction with the latest development version of the [Aura Router package](https://github.com/auraphp/Aura.Router/tree/3.x).

```
use Websoftwares\Middleware\MiddlewareRunner;
use Aura\Router\RouterContainer;

$routerContainer = new RouterContainer;
$map = $routerContainer->getMap();
$matcher = $routerContainer->getMatcher();

$middleware = new MiddlewareRunner;

// response + middlewareOne decoration bar = $response->bar.' World';
};

$routeIndexAction = function($request, $response) {
    // Awesome sauce
    return $response;
};

// Add middleware
$middleware->add($middlewareTwo);

...
// Add more middleware
...

// Add route as last one
$middleware->add($routeIndexAction);

$map->get('index.read', '/',$middleware); // match($request);
$handler = $route->handler;

// Call
$handler($request, $response);
```

Adapters
--------

[](#adapters)

At the time of writing PSR-7 is almost on the horizon released :-) and their are many well written community supported HTTP orientated packages but most packages are not yet compliant.

To avoid mass rewrites of all these great packages or waiting for the author and or community to update them or holding out on the advantage of new compliant packages we can make use of the Adapter pattern to make them for example suitable for PSR-7 middleware.

Adapter RequestAuthenticatorAdapter example
-------------------------------------------

[](#adapter-requestauthenticatoradapter-example)

The package [acquia/http-hmac-php](https://github.com/acquia/http-hmac-php) is an implementation of the HTTP HMAC Spec in PHP We want to validate the signature throw an exception or continue the middleware stack if it is a valid signature.

```
use Websoftwares\Middleware\MiddlewareRunner;
use Acquia\Hmac\RequestSigner;
use Acquia\Hmac\RequestAuthenticator;
use Websoftwares\Middleware\Adapter\RequestAuthenticatorAdapter;

$middleware = new MiddlewareRunner;

// response + middlewareOne decoration bar = $response->bar.' World';
};

// Add middleware
$middleware->add($middlewareOne);

...
// Add more middleware
...

$authenticator = new RequestAuthenticator(new RequestSigner(), '+15 minutes');

// $keyLoader implements \Acquia\Hmac\KeyLoaderInterface
$authenticatorMiddleware = new RequestAuthenticatorAdapter($authenticator, $keyLoader);

$middleware->add($authenticatorMiddleware);

// Call
$m = $middleware;

$m($request, $response);
```

Changelog
---------

[](#changelog)

- v0.0.11: Updated psr-7 psr/http-message to 1.0 and renamed phly/http with zendframework/zend-diactoros
- v0.0.10: Logic to exit on response added
- v0.0.9: Added abstract adapter and first implementation "acquia/http-hmac-php" package

Testing
-------

[](#testing)

In the tests folder u can find several tests.

Acknowledgement
---------------

[](#acknowledgement)

Inspired by all the great middleware packages

- [Interpose](https://github.com/carbocation/interpose)
- [StackPHP](http://stackphp.com)
- [Conduit](https://github.com/bigeasy/conduit)
- [Conduit-php](https://github.com/phly/conduit)
- [Rack](https://github.com/rack/rack)

License
-------

[](#license)

The [MIT](http://opensource.org/licenses/MIT "MIT") License (MIT).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.6% 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 ~6 days

Total

4

Last Release

4015d ago

### Community

Maintainers

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

---

Top Contributors

[![websoftwares](https://avatars.githubusercontent.com/u/946561?v=4)](https://github.com/websoftwares "websoftwares (28 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

httpresponserequestmiddleware

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-server-middleware

Common interface for HTTP server-side middleware

18291.2M1.5k](/packages/psr-http-server-middleware)[idealo/php-middleware-stack

Implementation of HTTP Middleware PSR-15 specification

318.9k](/packages/idealo-php-middleware-stack)[elementaryframework/water-pipe

URL routing framework and requests/responses handler for PHP

254.6k4](/packages/elementaryframework-water-pipe)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)

PHPackages © 2026

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