Skip to content

procurios/middleware-dispatcher

Repository files navigation

Middleware Dispatcher

Build Status Coverage Status

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);

About

Simple PSR-15 compliant middleware dispatcher

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages