PHPackages                             hannesvdvreken/psr7-middlewares - 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. hannesvdvreken/psr7-middlewares

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

hannesvdvreken/psr7-middlewares
===============================

0.1.0(10y ago)34911MITPHPPHP &gt;=5.4

Since Sep 9Pushed 10y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (1)

**No longer maintained**

Create callable middlewares instead. Signature:

```
function (RequestInterface $request, ResponseInterface $response, callable $next) {
    // Do something with the request before passing it on.
    ...

    // Pass on to next middleware.
    $response = $next($request, $response);

    // Do something with the response after the next middleware has been called.
    ...

    // Return ultimate response object.
    return $response;
}
```

PSR-7 middlewares
=================

[](#psr-7-middlewares)

[![Latest Version](https://camo.githubusercontent.com/c746b98c549fea0d98c5c09e9b28a8bcce5647f97bc708b1cfebf23634e92f2c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f68616e6e657376647672656b656e2f707372372d6d6964646c6577617265732e7376673f7374796c653d666c61742d737175617265)](https://github.com/hannesvdvreken/psr7-middlewares/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/b06624fb3fc8766336afae152c99d3ab06c57b5cb4d331024056f7f4431d5043/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f68616e6e657376647672656b656e2f707372372d6d6964646c6577617265732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/hannesvdvreken/psr7-middlewares)[![Coverage Status](https://camo.githubusercontent.com/f002421dde9a20cbdc23ca1916825c8a426f2740b4116ff9f28fa9060da94ae1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f68616e6e657376647672656b656e2f707372372d6d6964646c6577617265732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hannesvdvreken/psr7-middlewares/code-structure)[![Quality Score](https://camo.githubusercontent.com/426f41ccd7c4f15005c85be8cd7ac7935526bdf72bfcb93354ca1f422eac2e72/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f68616e6e657376647672656b656e2f707372372d6d6964646c6577617265732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hannesvdvreken/psr7-middlewares)

Stackable middlewares for PSR-7 HTTP message objects.

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

[](#installation)

```
composer require hannesvdvreken/psr7-middlewares

```

Description
-----------

[](#description)

This package is a small library that helps you to construct a decorated array of middlewares.

There are 2 types of middlewares:

A `Kernel`, which is a middleware which can pass on the Request and Response object to the next layer. A `Core` object is usually the last layer of a list of middlewares. A core will always return a PSR-7 `ResponseInterface` object and never pass on the given `RequestInterface` object to a next layer. It will never have a next middleware set.

The `Builder` object helps in creating a composed `Core` which consists of a specified list of layers. Note that the builder object is immutable: thus it returns a different mutated object after each `push` and `unshift` call.

```
use Psr7Stack\Builder;

$builder = new Builder();

$session = new SessionMiddleware();
$throttle = new TrottleMiddleware();
$app = new App();

$builder = $buider->push($session)->push($throttle)->push($app);

$stack = $builder->resolve();
```

The returned `Stack` object can also be created with the static factory method `create`.

```
use Psr7Stack\Stack;

$stack = Stack::create([$session, $throttle, $app]);
```

The Stack object itself is also a Core middleware, so it can be used in a different composition of middlewares. This is how you can send a Request object through the different layers of middlewares:

```
$psrResponse = $stack->handle($psrRequest);
```

Extending
---------

[](#extending)

Creating a Core yourself:

```
use Psr7Stack\Core;
use Psr\Http\Message\RequestInterface;

class App implements Core
{
    /**
     * @param \Psr\Http\Message\RequestInterface $request
     *
     * @request \Psr\Http\Message\ResponseInterface
     */
    public function handle(RequestInterface $request)
    {
        // Call the router and return the response.
        return $response;
    }
}
```

Creating a Kernel:

```
use Psr7Stack\Kernel;
use Psr7Stack\Traits\NextCore;

class SessionMiddleware implements Kernel
{
    // Use trait to implement the setNextCore method.
    use NextCore;

    /**
     * @param \Psr\Http\Message\RequestInterface $request
     *
     * @request \Psr\Http\Message\ResponseInterface
     */
    public function handle(RequestInterface $request)
    {
        // Call the next core and return the response.
        $response = $this->next->handle($request);

        // Do something with the response and return it.
        ...

        return $response;
    }
}
```

Middlewares
-----------

[](#middlewares)

### Existing

[](#existing)

- League/route application core

### Ideas for more middlewares

[](#ideas-for-more-middlewares)

- Robots middleware. To return an environment specific robots.txt file.
- Any type of framework application
- Throttle middleware
- CORS middleware
- Cache middleware
- IP based Firewall middleware
- Logger middleware

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

[](#contributing)

Contributions are welcome. See the [contributions file](CONTRIBUTING.md) to know how to contribute.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3904d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1410358?v=4)[Hannes Van De Vreken](/maintainers/hannesvdvreken)[@hannesvdvreken](https://github.com/hannesvdvreken)

---

Top Contributors

[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (11 commits)")

---

Tags

httppsr-7middleware

### Embed Badge

![Health badge](/badges/hannesvdvreken-psr7-middlewares/health.svg)

```
[![Health](https://phpackages.com/badges/hannesvdvreken-psr7-middlewares/health.svg)](https://phpackages.com/packages/hannesvdvreken-psr7-middlewares)
```

###  Alternatives

[psr/http-server-middleware

Common interface for HTTP server-side middleware

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

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

586.6M81](/packages/laminas-laminas-stratigility)[middlewares/utils

Common utils for PSR-15 middleware packages

503.4M92](/packages/middlewares-utils)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.0M61](/packages/mezzio-mezzio-router)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

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