procurios / middleware-dispatcher
Simple PSR-15 compliant middleware dispatcher.
Installs: 2 698
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 7
Forks: 2
Open Issues: 0
Requires
- php: >=7.0
- psr/http-message: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2024-11-08 17:26:34 UTC
README
Simple PSR-15 compliant middleware dispatcher
Goal
The goal of this library is to provide a minimal implementation of the PSR-15 specification that is compatible with older callback middleware.
Installation
composer require procurios/middleware-dispatcher
Usage
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);