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. [Framework](/categories/framework)
4. /
5. dakujem/generic-middleware

ActiveLibrary[Framework](/categories/framework)

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

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

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

Since Nov 28Pushed 6mo 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 today

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 81% of packages

Maintenance47

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

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

2043d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/443067?v=4)[Andrej Rypo](/maintainers/dakujem)[@dakujem](https://github.com/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

[cakephp/authentication

Authentication plugin for CakePHP

1214.1M106](/packages/cakephp-authentication)[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.

13745.8k4](/packages/chubbyphp-chubbyphp-framework)[kafkiansky/symfony-middleware

PSR-15 Middleware for symfony.

8069.1k](/packages/kafkiansky-symfony-middleware)[yiisoft/csrf

Yii CSRF Protection Library

27284.3k12](/packages/yiisoft-csrf)[yiisoft/session

A session service, PSR-15 session middleware, and a flash message service which helps use one-time messages.

20349.9k16](/packages/yiisoft-session)[igniphp/framework

Swoole, PSR-7, PSR-15 modular micro anti-framework.

2651.0k1](/packages/igniphp-framework)

PHPackages © 2026

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