Skip to content
PHP Ecosystem
Explore

Collector

API reference › Debug › collectors › Collector

abstract classyii\debug\collectors\Collector
ImplementsCollectorInterface
Sourcesrc/collectors/Collector.php
12 subclasses

Base class for the Yii2 debug collectors.

Owns the idempotent startup/shutdown lifecycle, the debug-module context, and the single encoding step that turns the typed snapshot returned by snapshot() into the persisted payload; subclasses hook event subscription into start() / stop() and read accumulated log messages through getLogMessages().

PropertyTypeDescriptionDefined by
$moduleyii\debug\Module|nullDebug module supplying the log target and sibling collectors, assigned by the module on registration. Default: null.Collector
MethodDescriptionDefined by
capture() finalEncodes the typed snapshot built by the subclass into the payload persisted for the panel.Collector
instrument()Installs low-level instrumentation as soon as the module registers the collector, before the panels are built.Collector
shutdown() finalDeactivates the collector once, releasing any subscription created by start().Collector
startup() finalActivates the collector once at the start of the request lifecycle.Collector
getLogMessages() protectedReturns the accumulated log messages, optionally filtered by level, category, and exclusion lists.Collector
getLogTarget() protectedReturns the initialized log target of the owning debug module.Collector
isStarted() protectedReturns whether the collector is active for the current request.Collector
snapshot() protected abstractBuilds the typed snapshot for the current request.Collector
start() protectedHook invoked once when the collector activates; subclasses subscribe to framework events here.Collector
stop() protectedHook invoked once when the collector deactivates; subclasses detach subscriptions and clear state here.Collector
final public function capture(): array<string, mixed>|null

Encodes the typed snapshot built by the subclass into the payload persisted for the panel.

Returns

array<string, mixed>|null: Encoded panel payload; null when the collector recorded nothing.

public function instrument(): void

Installs low-level instrumentation as soon as the module registers the collector, before the panels are built.

Module::initCollectors() calls this hook while the debugger is still bootstrapping, so a subclass whose data would otherwise miss the debugger’s own bootstrap work (queries issued by a panel constructor, for instance) can hook the framework here instead of waiting for start(). Implementations must be idempotent and must not depend on the log target, which is wired later.

The default implementation does nothing.

final public function shutdown(): void

Deactivates the collector once, releasing any subscription created by start().

final public function startup(): void

Activates the collector once at the start of the request lifecycle.

protected function getLogMessages(int $levels = 0, list<string> $categories = [], list<string> $except = [], Closure(mixed): string|null $formatter = null): list<yii\debug\collectors\LogTuple>

Returns the accumulated log messages, optionally filtered by level, category, and exclusion lists.

A PsrMessage payload also yields its PSR-3 context at tuple index 6, normalized and redacted through the module capture policy. A category value identical to the tuple category is dropped because it already names the row, as PsrLogger copies it there; any other category value stays in the context. Every other payload yields [].

Parameters

ParameterTypeDescription
$levelsintBitmask of yii\log\Logger::LEVEL_* values; 0 keeps every level.
$categorieslist<string>Category patterns to include; empty keeps every category.
$exceptlist<string>Category patterns to exclude.
$formatterClosure(mixed): string|nullCustom payload formatter; defaults to a readable string export.

Returns

list<yii\debug\collectors\LogTuple>: Canonical string-based log messages in capture order.

Throws

protected function getLogTarget(): yii\debug\LogTarget

Returns the initialized log target of the owning debug module.

Returns

yii\debug\LogTarget: Initialized log target.

Throws

protected function isStarted(): bool

Returns whether the collector is active for the current request.

Returns

bool: true while the collector is active for the request; false otherwise.

abstract protected function snapshot(): PHPForge\Debug\Storage\PanelSnapshot|null

Builds the typed snapshot for the current request.

Returns

PHPForge\Debug\Storage\PanelSnapshot|null: Typed payload, or null when the collector recorded nothing.

protected function start(): void

Hook invoked once when the collector activates; subclasses subscribe to framework events here.

protected function stop(): void

Hook invoked once when the collector deactivates; subclasses detach subscriptions and clear state here.