jerowork / middleware-request-handler
Minimalist PSR-15 middleware based request handler (dispatcher)
Installs: 2 385
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.5 || ^7.0 || ^8.0
- zendframework/zend-diactoros: ^1.7 || ^2.0
Suggests
- zendframework/zend-diactoros: As PSR-7 implementation
Provides
README
Minimalist PSR-15 middleware based request handler (dispatcher).
Installation
Install via Composer:
$ composer require jerowork/middleware-request-handler
Usage
Use with a PSR-7 request implementation, like Zend Diactoros.
Example
use Jerowork\MiddlewareDispatcher\Middleware\FinalResponseMiddleware; use Jerowork\MiddlewareDispatcher\MiddlewareRequestHandler; use Zend\Diactoros\Response; use Zend\Diactoros\Response\SapiEmitter; use Zend\Diactoros\ServerRequestFactory; // Setup a list of PSR-15 middlewares $middlewares = [ new SomeMiddleware(), new AnotherMiddleware() ]; // Setup request handler $handler = new MiddlewareRequestHandler($middlewares); // Add other middlewares after construct $handler->addMiddleware( new ThirdMiddleware(), new FourthMiddleware() ); // Add final reversal order middleware $handler->addMiddleware(new FinalResponseMiddleware(new Response()); // Handle a PSR-7 server request to response by the request handler (PSR-15) $response = $handler->handle(ServerRequestFactory::fromGlobals()); // Output PSR-7 response with a response emitter implementation of your choice (new SapiEmitter())->emit($response);