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

ActiveLibrary

dakujem/generic-middleware
==========================

Generic PSR-15 implementation: Turns callables into Handlers and Middleware.

1.0(5y ago)04.6k↓50%1UnlicensePHPPHP ^7.4 || ^8.0CI passing

Since Nov 28Pushed 4mo ago1 watchersCompare

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

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

Generic PSR-15 Middleware &amp; Handlers
========================================

[](#generic-psr-15-middleware--handlers)

[![PHP from Packagist](https://camo.githubusercontent.com/afdffdb631ff6973a69ba71545a5db10eced4d3b9be6f20ed1a1784800b7a8cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64616b756a656d2f67656e657269632d6d6964646c6577617265)](https://camo.githubusercontent.com/afdffdb631ff6973a69ba71545a5db10eced4d3b9be6f20ed1a1784800b7a8cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64616b756a656d2f67656e657269632d6d6964646c6577617265)[![Test Suite](https://github.com/dakujem/generic-middleware/actions/workflows/php-test.yml/badge.svg)](https://github.com/dakujem/generic-middleware/actions/workflows/php-test.yml)[![Coverage Status](https://camo.githubusercontent.com/5e95060c88c7f58b93c5e82f5c64aa1a3a445d9285816b2c41cf33626f83ab00/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f64616b756a656d2f67656e657269632d6d6964646c65776172652f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/dakujem/generic-middleware?branch=main)

> 💿 `composer require dakujem/generic-middleware`

Contains a couple of classes:

- `GenericMiddleware`, an implementation of `Psr\Http\Server\MiddlewareInterface`
- `GenericHandler`, an implementation of `Psr\Http\Server\RequestHandlerInterface`

> Note that I'm using aliases `Request`, `Response` and `Handler` for their respective PSR interface names for brevity.
>
> Consider the following `use` statements in use:
>
> ```
> use Psr\Http\Message\ServerRequestInterface  as Request;
> use Psr\Http\Message\ResponseInterface       as Response;
> use Psr\Http\Server\RequestHandlerInterface  as Handler;
> ```

`GenericMiddleware`
-------------------

[](#genericmiddleware)

The [`GenericMiddleware`](src/GenericMiddleware.php) is a general purpose middleware that turns a callable into a PSR-15 implementation. It accepts any callable with signature `fn(Request,Handler):Response`.

It can be used for convenient inline middleware implementation:

```
$app->add(new GenericMiddleware(function(Request $request, Handler $next): Response {
    $request = $request->withAttribute('foo', 42);
    $response = $next->handle($request);
    return $response->withHeader('foo', 'bar');
}));
```

`GenericHandler`
----------------

[](#generichandler)

The [`GenericHandler`](src/GenericHandler.php) is a general purpose request handler, as per the PSR-15 specification. It turns a callable with signature `fn(Request):Response` into a PSR-15 implementation.

It can be used for convenient inline handler implementation where you don't want to bother with neither anonymous classes nor named classes:

```
$kernel = new GenericHandler(
    fn() => new Response(404, 'Not Found')
);
$dispatcher = new MiddlewareDispatcher($kernel);
```

Testing
-------

[](#testing)

Run unit tests using the following command:

`$` `composer test`

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

[](#contributing)

Ideas, feature requests and other contribution is welcome. Please send a PR or create an issue.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance50

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

1997d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0bd7fa945013e9c0dcd65693575276bf5fcb9b9de13e1123e9f2c4a0a4c0fb6b?d=identicon)[dakujem](/maintainers/dakujem)

---

Top Contributors

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

---

Tags

middlewarepsr-15

### Embed Badge

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

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

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[tuupola/slim-basic-auth

PSR-7 and PSR-15 HTTP Basic Authentication Middleware

4442.0M26](/packages/tuupola-slim-basic-auth)[relay/relay

A PSR-15 server request handler.

3302.1M86](/packages/relay-relay)[tuupola/cors-middleware

PSR-7 and PSR-15 CORS middleware

1331.8M24](/packages/tuupola-cors-middleware)[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)

PHPackages © 2026

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