idiosyncratic / http-middlewarehandler
Simple PSR-15 Middleware Handler
1.0.2
2019-04-20 22:19 UTC
Requires
- php: >=7.3
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- doctrine/coding-standard: ^5.0
- nyholm/psr7: ^1.1
- phpstan/phpstan: ^0.11.2
- phpstan/phpstan-phpunit: ^0.11.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-10-25 08:47:17 UTC
README
Simple queue based PSR-15 Middleware Handler.
Installation
composer require idiosyncratic/http-middlewarehandler
Usage
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.