Skip to content
PHP Ecosystem
Explore

RequestCaptureMiddleware

API reference › Yii3 Debug › Middleware › RequestCaptureMiddleware

final readonly classYii3\Debug\Middleware\RequestCaptureMiddleware
ImplementsPsr\Http\Server\MiddlewareInterface
Sourcesrc/Middleware/RequestCaptureMiddleware.php

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.

MethodDescriptionDefined 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
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

ParameterTypeDescription
$rendererYii3\Debug\Web\ToolbarRendererRenderer producing the toolbar markup injected into the response.
$streamFactoryPsr\Http\Message\StreamFactoryInterfaceFactory building the rewritten response body.
$storePHPForge\Debug\Storage\SnapshotStoreStore the capture is written to.
$allowedIpRangesYiisoft\NetworkUtilities\IpRangesRanges allowed to reach the debugger.
$optionsToolbarOptionsSettings carrying the route prefix, the history size, the excessive-caller threshold, and the toolbar presentation.
$capturePolicyCapturePolicyPolicy deciding which values are persisted and which are redacted.
$collectorCoordinatorPHPForge\Debug\Collector\CollectorCoordinator|nullCoordinator owning the collectors, or null to capture nothing but the request summary.
$deferredCaptureYii3\Debug\Capture\DeferredCapture|nullHolder of the pending finalizer, or null to finalize inside the pipeline. Deferral requires a coordinator; without one the capture is finalized immediately.
public function process(Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Server\RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterface

Captures 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

ParameterTypeDescription
$requestPsr\Http\Message\ServerRequestInterfaceRequest reaching the middleware.
$handlerPsr\Http\Server\RequestHandlerInterfaceNext 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.