Simple PSR-15 compliant middleware dispatcher
The goal of this library is to provide a minimal implementation of the PSR-15 specification that is compatible with older callback middleware.
composer require procurios/middleware-dispatcher
See PSR-15 for detailed information about middleware dispatchers.
use Procurios\Http\MiddlewareDispatcher\Dispatcher;
$dispatcher = (new Dispatcher($myFallbackHandler))
->withMiddleware($myMiddleware)
->withMiddleware($myApp)
;
$response = $dispatcher->handle($request);
Or add anonymous callback middleware:
use Procurios\Http\MiddlewareDispatcher\Dispatcher;
$dispatcher = (new Dispatcher($myFallbackHandler))
->withMiddleware($myMiddleware)
->withCallback(function (ServerRequestInterface $request, callable $next) {
// noop
return $next($request);
})
->withCallback(function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
// noop
return $handler->handle($request);
})
->withMiddleware($myApp)
;
$response = $dispatcher->handle($request);