Collector
API reference › Debug › collectors › Collector
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().
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$module | yii\| | Debug module supplying the log target and sibling collectors, assigned by the module on registration. Default: null. | Collector |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
capture() final | Encodes 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() final | Deactivates the collector once, releasing any subscription created by start(). | Collector |
startup() final | Activates the collector once at the start of the request lifecycle. | Collector |
getLogMessages() protected | Returns the accumulated log messages, optionally filtered by level, category, and exclusion lists. | Collector |
getLogTarget() protected | Returns the initialized log target of the owning debug module. | Collector |
isStarted() protected | Returns whether the collector is active for the current request. | Collector |
snapshot() protected abstract | Builds the typed snapshot for the current request. | Collector |
start() protected | Hook invoked once when the collector activates; subclasses subscribe to framework events here. | Collector |
stop() protected | Hook invoked once when the collector deactivates; subclasses detach subscriptions and clear state here. | Collector |
Method details
Section titled “Method details”capture()
Section titled “capture() ”final public function capture(): array<string, mixed>|nullEncodes 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.
instrument()
Section titled “instrument() ”public function instrument(): voidInstalls 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.
shutdown()
Section titled “shutdown() ”final public function shutdown(): voidDeactivates the collector once, releasing any subscription created by start().
startup()
Section titled “startup() ”final public function startup(): voidActivates the collector once at the start of the request lifecycle.
getLogMessages()
Section titled “getLogMessages() ”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
| Parameter | Type | Description |
|---|---|---|
$levels | int | Bitmask of yii\ values; 0 keeps every level. |
$categories | list<string> | Category patterns to include; empty keeps every category. |
$except | list<string> | Category patterns to exclude. |
$formatter | Closure(mixed): string| | Custom payload formatter; defaults to a readable string export. |
Returns
list<yii\debug\collectors\LogTuple>: Canonical string-based log messages in capture order.
Throws
yii\base\InvalidConfigException: when the debug module log target is not initialized.
getLogTarget()
Section titled “getLogTarget() ”protected function getLogTarget(): yii\debug\LogTargetReturns the initialized log target of the owning debug module.
Returns
yii\debug\LogTarget: Initialized log target.
Throws
yii\base\InvalidConfigException: when the debug module log target is not initialized.
isStarted()
Section titled “isStarted() ”protected function isStarted(): boolReturns whether the collector is active for the current request.
Returns
bool: true while the collector is active for the request; false otherwise.
snapshot()
Section titled “snapshot() ”abstract protected function snapshot(): PHPForge\Debug\Storage\PanelSnapshot|nullBuilds the typed snapshot for the current request.
Returns
PHPForge\Debug\Storage\PanelSnapshot|null: Typed payload, or null when the collector recorded nothing.
start()
Section titled “start() ”protected function start(): voidHook invoked once when the collector activates; subclasses subscribe to framework events here.
stop()
Section titled “stop() ”protected function stop(): voidHook invoked once when the collector deactivates; subclasses detach subscriptions and clear state here.