Final Class Yiisoft\Yii\Debug\Debugger
| Inheritance | Yiisoft\Yii\Debug\Debugger |
|---|
Debugger collects data from collectors and stores it in a storage.
Psalm Types
| Name | Value |
|---|---|
| TSummary | array{id: non-empty-string, collectors: list<non-empty-string>, summary: array<non-empty-string, array>} |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\Debug\Debugger | |
| getId() | Returns ID of the current request. | Yiisoft\Yii\Debug\Debugger |
| isActive() | Returns whether debugger is active. | Yiisoft\Yii\Debug\Debugger |
| kill() | Stops the debugger from listening. Collected data will not be flushed to storage. | Yiisoft\Yii\Debug\Debugger |
| start() | Starts debugger and collectors. | Yiisoft\Yii\Debug\Debugger |
| stop() | Stops the debugger for listening. Collected data will be flushed to storage. | Yiisoft\Yii\Debug\Debugger |
Method Details
public function __construct(
private readonly StorageInterface $storage,
array $collectors,
private readonly DebuggerStartupPolicyInterface $debuggerStartupPolicy = new AlwaysOnDebuggerPolicy(),
private readonly CollectorStartupPolicyInterface $collectorStartupPolicy = new AllowAllCollectorPolicy(),
array $excludedClasses = [],
) {
$preparedCollectors = [];
foreach ($collectors as $collector) {
$preparedCollectors[$collector->getName()] = $collector;
}
$this->collectors = $preparedCollectors;
$this->dataNormalizer = new DataNormalizer($excludedClasses);
register_shutdown_function([$this, 'stop']);
}
Returns ID of the current request.
Throws LogicException if debugger is not started. Use isActive() to check if debugger is active.
| public getId( ): string | ||
| return | string |
ID of the current request. |
|---|---|---|
public function getId(): string
{
return $this->id ?? throw new LogicException('Debugger is not started.');
}
Returns whether debugger is active.
| public isActive( ): boolean | ||
| return | boolean |
Whether debugger is active. |
|---|---|---|
public function isActive(): bool
{
return $this->id !== null;
}
Stops the debugger from listening. Collected data will not be flushed to storage.
| public kill( ): void |
public function kill(): void
{
if (!$this->isActive()) {
return;
}
$this->deactivate();
}
Starts debugger and collectors.
| public start( object $event ): void | ||
| $event | object |
Event that triggered debugger startup. |
public function start(object $event): void
{
if (!$this->allowStart) {
return;
}
if (!$this->debuggerStartupPolicy->satisfies($event)) {
$this->allowStart = false;
$this->kill();
return;
}
if ($this->isActive()) {
return;
}
/** @var non-empty-string */
$this->id = str_replace('.', '', uniqid('', true));
foreach ($this->collectors as $collector) {
if ($this->collectorStartupPolicy->satisfies($collector, $event)) {
$collector->startup();
}
}
}
Signup or Login in order to comment.