Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 2.45 KB

README.md

File metadata and controls

63 lines (43 loc) · 2.45 KB

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