Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Debugger life cycle #308

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/di-console.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
),
'excludedClasses' => $params['yiisoft/yii-debug']['excludedClasses'],
],
'reset' => function () {
/** @var Debugger $this */
$this->allowStart = true;
},
],
];
4 changes: 4 additions & 0 deletions config/di-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@
),
'excludedClasses' => $params['yiisoft/yii-debug']['excludedClasses'],
],
'reset' => function () {
/** @var Debugger $this */
$this->allowStart = true;
},
],
];
25 changes: 20 additions & 5 deletions src/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ final class Debugger
*/
private readonly DataNormalizer $dataNormalizer;

/**
* @var string|null ID of the current request. `null` if debugger is not active.
*/
private ?string $id = null;

/**
* @var bool Whether debugger startup is allowed.
*/
private bool $allowStart = true;

/**
* @param StorageInterface $storage The storage to store collected data.
* @param CollectorInterface[] $collectors Collectors to be used.
Expand Down Expand Up @@ -57,11 +67,6 @@ public function __construct(
register_shutdown_function([$this, 'stop']);
}

/**
* @var string|null ID of the current request. `null` if debugger is not active.
*/
private ?string $id = null;

/**
* Returns whether debugger is active.
*
Expand Down Expand Up @@ -91,7 +96,17 @@ public function getId(): string
*/
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;
}

Expand Down
Loading