Middleware Dispatcher
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
}
}