mehr-it / eli-middleware-chain
Chaining for PSR-15 middleware
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/mehr-it/eli-middleware-chain
Requires
- php: >=7.1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7.4|^8.0
This package is auto-updated.
Last update: 2025-10-26 10:52:40 UTC
README
When defining a request processing chain, usually more than one middleware is involved into the
processing chain. The ChainHandler allows to define the PSR-15 middleware processing stack as
array or iterator:
$chain = new ChainHandler([
      new MiddlewareA(),
      new MiddlewareB(),
], $next); 
This makes code much more readable and allows easy dynamic configuration of the middleware chain.
To create middleware instances on the fly - only when needed - resolver functions may be used:
$chain = new ChainHandler([
      function() { return new MiddlewareA(); },
      function() { return new MiddlewareB(); },
], $next); 
Middleware instead of handler
Sometimes a middleware chain is required as middleware itself. The ChainMiddleware can be used
for such purposes. It's usage is straightforward as the ChainHandler:
$chain = new ChainMiddleware([
      new MiddlewareA(),
      new MiddlewareB(),
]);