acelot/middleware-dispatcher

PSR-15 compliant middleware dispatcher

1.0.0 2018-08-01 04:47 UTC

README

packagist deps license

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