8000 [FrameworkBundle] Fix wiring ConsoleProfilerListener · symfony/framework-bundle@45e3acf · GitHub
[go: up one dir, main page]

Skip to content

Commit 45e3acf

Browse files
[FrameworkBundle] Fix wiring ConsoleProfilerListener
1 parent 66b7df1 commit 45e3acf

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

EventListener/ConsoleProfilerListener.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ final class ConsoleProfilerListener implements EventSubscriberInterface
3838
/** @var \SplObjectStorage<Request, ?Request> */
3939
private \SplObjectStorage $parents;
4040

41+
private bool $disabled = false;
42+
4143
public function __construct(
4244
private readonly Profiler $profiler,
4345
private readonly RequestStack $requestStack,
@@ -66,7 +68,7 @@ public function initialize(ConsoleCommandEvent $event): void
6668

6769
$input = $event->getInput();
6870
if (!$input->hasOption('profile') || !$input->getOption('profile')) {
69-
$this->profiler->disable();
71+
$this->disabled = true;
7072

7173
return;
7274
}
@@ -92,7 +94,12 @@ public function catch(ConsoleErrorEvent $event): void
9294

9395
public function profile(ConsoleTerminateEvent $event): void
9496
{
95-
if (!$this->cliMode || !$this->profiler->isEnabled()) {
97+
$error = $this->error;
98+
$this->error = null;
99+
100+
if (!$this->cliMode || $this->disabled) {
101+
$this->disabled = false;
102+
96103
return;
97104
}
98105

@@ -114,8 +121,7 @@ public function profile(ConsoleTerminateEvent $event): void
114121
$request->command->exitCode = $event->getExitCode();
115122
$request->command->interruptedBySignal = $event->getInterruptingSignal();
116123

117-
$profile = $this->profiler->collect($request, $request->getResponse(), $this->error);
118-
$this->error = null;
124+
$profile = $this->profiler->collect($request, $request->getResponse(), $error);
119125
$this->profiles[$request] = $profile;
120126

121127
if ($this->parents[$request] = $this->requestStack->getParentRequest()) {

Resources/config/profiling.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@
4040

4141
->set('console_profiler_listener', ConsoleProfilerListener::class)
4242
->args([
43-
service('profiler'),
43+
service('.lazy_profiler'),
4444
service('.virtual_request_stack'),
4545
service('debug.stopwatch'),
4646
param('kernel.runtime_mode.cli'),
4747
service('router')->nullOnInvalid(),
4848
])
4949
->tag('kernel.event_subscriber')
5050

51+
->set('.lazy_profiler', Profiler::class)
52+
->factory('current')
53+
->args([[service('profiler')]])
54+
->lazy()
55+
5156
->set('.virtual_request_stack', VirtualRequestStack::class)
5257
->args([service('request_stack')])
5358
->public()

0 commit comments

Comments
 (0)
0