Dead simple PSR-15 middleware dispatcher
Switch branches/tags
Clone or download
Latest commit b62974a Oct 17, 2018

README.md

Northwoods Broker

Become a Supporter Latest Stable Version License Build Status Code Coverage Scrutinizer Code Quality

Broker is a dead simple PSR-15 middleware dispatcher. Broker implements both RequestHandlerInterface and MiddlewareInterface for maximum flexibility.

Install

composer require northwoods/broker

Usage

use Acme\Middleware;
use Northwoods\Broker\Broker;

/** @var \Psr\Http\Message\ServerRequestInterface */
$request = /* any server request */;

// Use append() or prepend() to add middleware
$broker = new Broker();
$broker->append(new Middleware\ParseRequest());
$broker->prepend(new Middleware\CheckIp());

/** @var \Psr\Http\Message\ResponseInterface */
$response = $broker->handle($request);

append(...$middleware)

Add one or more middleware to the end of the stack.

prepend(...$middleware)

Add one or more middleware to be beginning of the stack.

handle($request)

Dispatch the middleware stack as a request handler. If the end of the stack is reached and no response has been generated, an OutOfBoundsException will be thrown.

process($request, $handler)

Dispatch the middleware stack as a middleware. If the end of the stack is reached and no response has been generated, the $handler will be called.

Suggested Packages