From 8a1ced3f63b166b499e56218be774f26ae3a7cd8 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sat, 9 Dec 2023 12:34:14 +0100 Subject: [PATCH] [FrameworkBundle] Fix profiling command in web context --- .../EventListener/ConsoleProfilerListener.php | 11 ++++++++++- .../FrameworkBundle/Resources/config/profiling.php | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php index d3fc3810631b6..869bd73c8c951 100644 --- a/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php @@ -42,6 +42,7 @@ public function __construct( private readonly Profiler $profiler, private readonly RequestStack $requestStack, private readonly Stopwatch $stopwatch, + private readonly bool $cliMode, private readonly UrlGeneratorInterface $urlGenerator, ) { $this->profiles = new \SplObjectStorage(); @@ -59,6 +60,10 @@ public static function getSubscribedEvents(): array public function initialize(ConsoleCommandEvent $event): void { + if (!$this->cliMode) { + return; + } + $input = $event->getInput(); if (!$input->hasOption('profile') || !$input->getOption('profile')) { $this->profiler->disable(); @@ -78,12 +83,16 @@ public function initialize(ConsoleCommandEvent $event): void public function catch(ConsoleErrorEvent $event): void { + if (!$this->cliMode) { + return; + } + $this->error = $event->getError(); } public function profile(ConsoleTerminateEvent $event): void { - if (!$this->profiler->isEnabled()) { + if (!$this->cliMode || !$this->profiler->isEnabled()) { return; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php index ec764d8375665..d863cd8b1db7e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php @@ -43,6 +43,7 @@ service('profiler'), service('.virtual_request_stack'), service('debug.stopwatch'), + param('kernel.runtime_mode.cli'), service('router'), ]) ->tag('kernel.event_subscriber')