PHPackages                             oscarotero/middleland - 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. oscarotero/middleland

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

oscarotero/middleland
=====================

PSR-15 middleware dispatcher

v1.0.3(1y ago)3781.0k↓48%56MITPHPPHP ^7.1|^8.0CI passing

Since Jan 9Pushed 1y ago4 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (13)Used By (6)

Middleland
==========

[](#middleland)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d2a0077345d161c551aa657b548efc937ee1e544433f51c4ebd5723d04d96a23/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f736361726f7465726f2f6d6964646c656c616e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oscarotero/middleland)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Simple (but powerful) [PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md)middleware dispatcher:

Requirements
------------

[](#requirements)

- PHP 7
- A [PSR-7 Message implementation](http://www.php-fig.org/psr/psr-7/), for example [laminas-diactoros](https://github.com/laminas/laminas-diactoros)
- Optionally, a [PSR-11 container](https://github.com/php-fig/container)implementation to create the middleware components on demand.

Example
-------

[](#example)

```
use Middleland\Dispatcher;

$middleware = [
    new Middleware1(),
    new Middleware2(),
    new Middleware3(),

    // A dispatcher can be used to group middlewares
    new Dispatcher([
        new Middleware4(),
        new Middleware5(),
    ]),

    // You can use closures
    function ($request, $next) {
        $response = $next->handle($request);
        return $response->withHeader('X-Foo', 'Bar');
    },

    // Or use a string to create the middleware on demand using a PSR-11 container
    'middleware6'

    // USE AN ARRAY TO ADD CONDITIONS:

    // This middleware is processed only in paths starting by "/admin"
    ['/admin', new MiddlewareAdmin()],

    // This is processed in DEV
    [ENV === 'DEV', new MiddlewareAdmin()],

    // Use callables to create other conditions
    [
        function ($request) {
            return $request->getUri()->getScheme() === 'https';
        },
        new MiddlewareHttps()
    ],

    // There are some matchers included in this library to create conditions
    [
        new Pattern('*.png'),
        new MiddlewareForPngFiles()
    ],

    //And use several for each middleware
    [
        ENV === 'DEV',
        new Pattern('*.png'),
        new MiddlewareForPngFilesInDev()
    ],
];

$dispatcher = new Dispatcher($middleware, new Container());

$response = $dispatcher->dispatch(new Request());
```

Matchers
--------

[](#matchers)

As you can see in the example above, you can use an array of "matchers" to filter the requests that receive middlewares. You can use callables, instances of `Middleland\Matchers\MatcherInterface` or booleans, but for comodity, the string values are also used to create `Middleland\Matchers\Path` instances. The available matchers are:

NameDescriptionExample`Path`Filter requests by base path. Use exclamation mark for negative matches`new Path('/admin')`, `new Path('!/not-admin')``Pattern`Filter requests by path pattern. Use exclamation mark for negative matches`new Pattern('*.png')` `new Pattern('!*.jpg')``Accept`Filter requests by Accept header. Use exclamation mark for negative matches`new Accept('text/html')` `new Accept('!image/png')`How to create matchers
----------------------

[](#how-to-create-matchers)

Just use a callable or an instance of the `Middleland\Matchers\MatcherInterface`. Example:

```
use Middleland\Matchers\MatcherInterface;
use Psr\Http\Message\ServerRequestInterface;

class IsAjax implements MatcherInterface
{
    public function __invoke(ServerRequestInterface $request): bool
    {
    	return $request->getHeaderLine('X-Requested-With') === 'xmlhttprequest';
	}
}
```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes.

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

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance46

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 85.9% 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 ~274 days

Recently: every ~662 days

Total

12

Last Release

400d ago

Major Versions

v0.7.1 → v1.0.02018-01-24

PHP version history (3 changes)v0.1.0PHP ^7.0

v1.0.1PHP ^7.0|^8.0

v1.0.2PHP ^7.1|^8.0

### Community

Maintainers

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

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (55 commits)")[![fisharebest](https://avatars.githubusercontent.com/u/2306088?v=4)](https://github.com/fisharebest "fisharebest (2 commits)")[![jan-di](https://avatars.githubusercontent.com/u/23323185?v=4)](https://github.com/jan-di "jan-di (2 commits)")[![kfreiman](https://avatars.githubusercontent.com/u/2056294?v=4)](https://github.com/kfreiman "kfreiman (2 commits)")[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (1 commits)")[![raisoblast](https://avatars.githubusercontent.com/u/753819?v=4)](https://github.com/raisoblast "raisoblast (1 commits)")[![tbreuss](https://avatars.githubusercontent.com/u/1334161?v=4)](https://github.com/tbreuss "tbreuss (1 commits)")

---

Tags

dispatcherhttpmiddlewarepsr-15httppsr-7middlewarepsr-15

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/oscarotero-middleland/health.svg)

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

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[middlewares/utils

Common utils for PSR-15 middleware packages

503.4M92](/packages/middlewares-utils)[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

586.6M81](/packages/laminas-laminas-stratigility)[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)
