Simple PSR-15 Middleware Handler

1.0.2 2019-04-20 22:19 UTC

This package is auto-updated.

Last update: 2023-05-25 05:26:55 UTC


Simple queue based PSR-15 Middleware Handler.


composer require idiosyncratic/http-middlewarehandler


Composing an instance requires:

  • A fallback request handler implementing Psr\Http\Server\RequestHandlerInterface
  • One or more middlewares implementing Psr\Http\Server\MiddlewareInterface
use Idiosyncratic\Http\Middleware\MiddlewareRequestHandler;

$handler = new MiddlewareRequestHandler(
    new PsrRequestHandler(),
    new PsrMiddlewareOne(),
    new PsrMiddlewareTwo(),
    new PsrMiddlewareThree(),

$response = $handler->handle($psrServerRequest);

While most PHP applications are designed so that script lifetime is for a single request, MiddlewareRequestHandler is designed to be usable in long lived scripts, such as an application built with a ReactPHP or a similar library. Therefore, it is expected that middlewares and the services that they use are stateless as a single instance may service multiple requests.