Dead simple PSR-15 middleware dispatcher
Broker is a dead simple PSR-15 middleware dispatcher. Broker implements
MiddlewareInterface for maximum flexibility.
composer require northwoods/broker
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);
Add one or more middleware to the end of the stack.
Add one or more middleware to be beginning of the stack.
Dispatch the middleware stack as a request handler. If the end of the stack is
reached and no response has been generated, an
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.