DeferredCapture
API reference › Yii3 Debug › Capture › DeferredCapture
Holds the pending capture finalizer until the application reaches its shutdown phase.
Writing the capture from the middleware misses everything produced after the pipeline returns: a lazily rendered
response body, log and profiler flushes, and the events dispatched around emission. Deferring the finalizer to
Yiisoft\Yii\Http\Event\ApplicationShutdown keeps those in the snapshot, and the registered PHP shutdown fallback
still writes it when the application never dispatches that event.
While the request handler runs, arm() keeps a second, separate fallback for the capture in progress, so a
script that ends inside the handler, through exit, dd(), or a fatal error, still writes it, as the Yii2 logger
flush does at shutdown.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a deferred finalizer using the supplied shutdown registrar or PHP’s default registrar. | DeferredCapture |
arm() | Stores the fallback that writes the capture in progress when the script ends before the request handler returns. | DeferredCapture |
cancel() | Drops the pending finalizer without running it. | DeferredCapture |
defer() | Stores the finalizer to run at shutdown, finalizing a capture still pending from an earlier request. | DeferredCapture |
disarm() | Drops the fallback arm() stored, once the request handler returned or failed. | DeferredCapture |
finalize() | Runs the pending finalizer exactly once, clearing it first so a second call stays a no-op. | DeferredCapture |
isPending() | Reports whether a deferred finalizer is waiting to run. | DeferredCapture |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(Closure(callable(): void): void|null $shutdownRegistrar = null)Creates a deferred finalizer using the supplied shutdown registrar or PHP’s default registrar.
Parameters
| Parameter | Type | Description |
|---|---|---|
$shutdownRegistrar | Closure(callable(): void): void| | Registrar receiving the shutdown fallback, or null to register it with PHP itself. |
arm()
Section titled “arm() ”public function arm(Closure(): void $fallback): voidStores the fallback that writes the capture in progress when the script ends before the request handler returns.
The fallback is kept apart from the pending finalizer, so a defer() or finalize() reached while the
handler runs never writes the capture in progress; only the PHP shutdown fallback runs it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fallback | Closure(): void | Finalizer writing the capture of the request being handled. |
cancel()
Section titled “cancel() ”public function cancel(): voidDrops the pending finalizer without running it.
defer()
Section titled “defer() ”public function defer(Closure(): void $finalizer): voidStores the finalizer to run at shutdown, finalizing a capture still pending from an earlier request.
Parameters
| Parameter | Type | Description |
|---|---|---|
$finalizer | Closure(): void | Finalizer writing the capture. |
disarm()
Section titled “disarm() ”public function disarm(): voidDrops the fallback arm() stored, once the request handler returned or failed.
finalize()
Section titled “finalize() ”public function finalize(): voidRuns the pending finalizer exactly once, clearing it first so a second call stays a no-op.
isPending()
Section titled “isPending() ”public function isPending(): boolReports whether a deferred finalizer is waiting to run.
Returns
bool: true when a finalizer is waiting to run; false otherwise.