acelot / middleware-dispatcher
PSR-15 compliant middleware dispatcher
Installs: 1 416
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.1
- psr/container: ^1.0
- psr/http-server-middleware: ^1.0
Suggests
- acelot/resolver: To resolve middleware dependencies
- php-di/php-di: To resolve middleware dependencies
This package is auto-updated.
Last update: 2024-11-07 02:09:23 UTC
README
PSR-15 compliant middleware dispatcher.
Install
composer require acelot/middleware-dispatcher
Also you need to install some PSR-11 compliant DI container like acelot/resolver
or php-di/php-di
.
Example
entrypoint.php
$resolver = new Psr11CompliantDiContainer(); $dispatcher = new MiddlewareDispatcher($resolver, [ FirstMiddleware::class, SecondMiddleware::class, ThirdMiddleware::class, ..., LastMiddleware::class ]); $response = $dispatcher->handle($serverRequest);
FirstMiddleware.php
class FirstMiddleware implements MiddlewareInterface { public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { // Request handler } }