procurios/middleware-dispatcher

Simple PSR-15 compliant middleware dispatcher.

1.0.1 2018-01-29 15:38 UTC

This package is auto-updated.

Last update: 2024-11-08 17:26:34 UTC


README

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