Skip to content

Commit eb01a60

Browse files
authored
Modify Debugger life cycle (#308)
1 parent b36226b commit eb01a60

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

config/di-console.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@
3030
),
3131
'excludedClasses' => $params['yiisoft/yii-debug']['excludedClasses'],
3232
],
33+
'reset' => function () {
34+
/** @var Debugger $this */
35+
$this->allowStart = true;
36+
},
3337
],
3438
];

config/di-web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@
3232
),
3333
'excludedClasses' => $params['yiisoft/yii-debug']['excludedClasses'],
3434
],
35+
'reset' => function () {
36+
/** @var Debugger $this */
37+
$this->allowStart = true;
38+
},
3539
],
3640
];

src/Debugger.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ final class Debugger
3030
*/
3131
private readonly DataNormalizer $dataNormalizer;
3232

33+
/**
34+
* @var string|null ID of the current request. `null` if debugger is not active.
35+
*/
36+
private ?string $id = null;
37+
38+
/**
39+
* @var bool Whether debugger startup is allowed.
40+
*/
41+
private bool $allowStart = true;
42+
3343
/**
3444
* @param StorageInterface $storage The storage to store collected data.
3545
* @param CollectorInterface[] $collectors Collectors to be used.
@@ -57,11 +67,6 @@ public function __construct(
5767
register_shutdown_function([$this, 'stop']);
5868
}
5969

60-
/**
61-
* @var string|null ID of the current request. `null` if debugger is not active.
62-
*/
63-
private ?string $id = null;
64-
6570
/**
6671
* Returns whether debugger is active.
6772
*
@@ -91,7 +96,17 @@ public function getId(): string
9196
*/
9297
public function start(object $event): void
9398
{
99+
if (!$this->allowStart) {
100+
return;
101+
}
102+
94103
if (!$this->debuggerStartupPolicy->satisfies($event)) {
104+
$this->allowStart = false;
105+
$this->kill();
106+
return;
107+
}
108+
109+
if ($this->isActive()) {
95110
return;
96111
}
97112

0 commit comments

Comments
 (0)