Skip to content
PHP Ecosystem
Explore

DeferredCapture

API reference › Yii3 Debug › Capture › DeferredCapture

final classYii3\Debug\Capture\DeferredCapture
Sourcesrc/Capture/DeferredCapture.php

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.

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

ParameterTypeDescription
$shutdownRegistrarClosure(callable(): void): void|nullRegistrar receiving the shutdown fallback, or null to register it with PHP itself.
public function arm(Closure(): void $fallback): void

Stores 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

ParameterTypeDescription
$fallbackClosure(): voidFinalizer writing the capture of the request being handled.
public function cancel(): void

Drops the pending finalizer without running it.

public function defer(Closure(): void $finalizer): void

Stores the finalizer to run at shutdown, finalizing a capture still pending from an earlier request.

Parameters

ParameterTypeDescription
$finalizerClosure(): voidFinalizer writing the capture.
public function disarm(): void

Drops the fallback arm() stored, once the request handler returned or failed.

public function finalize(): void

Runs the pending finalizer exactly once, clearing it first so a second call stays a no-op.

public function isPending(): bool

Reports whether a deferred finalizer is waiting to run.

Returns

bool: true when a finalizer is waiting to run; false otherwise.