Skip to content
docsv0.9.1

MiddlewarePipeline

A minimal PSR-15 relay that composes a route's `middleware[]` in front of its resolved handler: `middleware[0]` wraps `middleware[1]` wraps … wraps the `$tip` handler, so the middlewares run in declaration order and the innermost call is the controller. Immutable and re-entrant by design: each step advances by handing the next middleware a NEW pipeline pinned one index deeper, rather than mutating a shared cursor — so a middleware that short-circuits (returns without calling `$handler->handle()`) simply never advances, and the same pipeline instance can be handled more than once without state bleeding between runs.

MiddlewarePipeline::__construct()

public function __construct(array $queue, Psr\Http\Server\RequestHandlerInterface $tip, int $index = 0):

Parameters

Parameters of __construct()
NameTypeDescription
$queuelist<MiddlewareInterface>the route's middlewares, in declaration order
$tipRequestHandlerInterfacethe resolved route handler, run once the queue is exhausted
$indexintthe middleware this pipeline will invoke next

MiddlewarePipeline::handle()

public function handle(Psr\Http\Message\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface

Invokes the middleware at the current index (advancing to the next), or the tip handler when the queue is spent.

Parameters

Parameters of handle()
NameTypeDescription
$requestPsr\Http\Message\ServerRequestInterface