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 mixed __construct ( Yiisoft\Yii\Debug\Storage\StorageInterface $storage, Yiisoft\Yii\Debug\Collector\CollectorInterface[] $collectors, Yiisoft\Yii\Debug\StartupPolicy\Debugger\DebuggerStartupPolicyInterface $debuggerStartupPolicy = new AlwaysOnDebuggerPolicy(), Yiisoft\Yii\Debug\StartupPolicy\Collector\CollectorStartupPolicyInterface $collectorStartupPolicy = new AllowAllCollectorPolicy(), array $excludedClasses = [] ) | ||
| $storage | Yiisoft\Yii\Debug\Storage\StorageInterface |
The storage to store collected data. |
| $collectors | Yiisoft\Yii\Debug\Collector\CollectorInterface[] |
Collectors to be used. |
| $debuggerStartupPolicy | Yiisoft\Yii\Debug\StartupPolicy\Debugger\DebuggerStartupPolicyInterface |
Policy to decide whether debugger should be started. Default {@see \Yiisoft\Yii\Debug\StartupPolicy\Debugger\AlwaysOnDebuggerPolicy} that always allows to startup debugger. |
| $collectorStartupPolicy | Yiisoft\Yii\Debug\StartupPolicy\Collector\CollectorStartupPolicyInterface |
Policy to decide whether collector should be started. Default {@see \Yiisoft\Yii\Debug\StartupPolicy\Collector\AllowAllCollectorPolicy} that always allows to use all collectors. |
| $excludedClasses | array |
List of classes to be excluded from collected data before storing. |
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 {@see \Yiisoft\Yii\Debug\isActive()} to check if debugger is active.
| public string getId ( ) | ||
| 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 boolean isActive ( ) | ||
| 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 void kill ( ) |
public function kill(): void
{
if (!$this->isActive()) {
return;
}
$this->deactivate();
}
Starts debugger and collectors.
| public void start ( object $event ) | ||
| $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.