RequestCaptureMiddleware
API reference › Yii3 Debug › Middleware › RequestCaptureMiddleware
Captures debug snapshots and injects the toolbar into eligible HTML responses.
Requests targeting the debugger pass through uncaptured, so DebugRouteMiddleware can serve them whichever of
the two runs first, and an application that answers the debugger paths itself can register this middleware alone.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates request-capture middleware with toolbar rendering, storage, policy, and optional collectors. | RequestCaptureMiddleware |
process() | Captures the request, then injects the toolbar into an eligible HTML response. | RequestCaptureMiddleware |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(Yii3\Debug\Web\ToolbarRenderer $renderer, Psr\Http\Message\StreamFactoryInterface $streamFactory, PHPForge\Debug\Storage\SnapshotStore $store, Yiisoft\NetworkUtilities\IpRanges $allowedIpRanges, Yii3\Debug\Middleware\ToolbarOptions $options, PHPForge\Debug\Capture\CapturePolicy $capturePolicy, PHPForge\Debug\Collector\CollectorCoordinator|null $collectorCoordinator, Yii3\Debug\Capture\DeferredCapture|null $deferredCapture)Creates request-capture middleware with toolbar rendering, storage, policy, and optional collectors.
Parameters
| Parameter | Type | Description |
|---|---|---|
$renderer | Yii3\ | Renderer producing the toolbar markup injected into the response. |
$streamFactory | Psr\ | Factory building the rewritten response body. |
$store | PHPForge\ | Store the capture is written to. |
$allowedIpRanges | Yiisoft\ | Ranges allowed to reach the debugger. |
$options | ToolbarOptions | Settings carrying the route prefix, the history size, the excessive-caller threshold, and the toolbar presentation. |
$capturePolicy | CapturePolicy | Policy deciding which values are persisted and which are redacted. |
$collectorCoordinator | PHPForge\ | Coordinator owning the collectors, or null to capture nothing but the request summary. |
$deferredCapture | Yii3\| | Holder of the pending finalizer, or null to finalize inside the pipeline. Deferral requires a coordinator; without one the capture is finalized immediately. |
process()
Section titled “process() ”public function process(Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Server\RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterfaceCaptures the request, then injects the toolbar into an eligible HTML response.
A capture still pending from an earlier request is written before anything else, debugger pages and requests
from a disallowed address included: a worker that never dispatched the shutdown event stops the collectors
before serving them, so their activity stays out of that capture, and the capture reaches history at once. A
failing finalization propagates from the request that triggered it. DebugRouteMiddleware applies the
same rule, so the guarantee holds whichever of the two runs first.
Requests targeting the debugger itself and requests from a disallowed address pass through untouched.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Psr\ | Request reaching the middleware. |
$handler | Psr\ | Next handler in the middleware stack. |
Returns
Psr\Http\Message\ResponseInterface: Response, with the toolbar injected when the request qualifies.
Throws
Throwable: when the pending capture or the request handler fails.