diff --git a/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php b/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php index 869bd73c8c951..c2a71d0a7cf50 100644 --- a/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/EventListener/ConsoleProfilerListener.php @@ -43,7 +43,7 @@ public function __construct( private readonly RequestStack $requestStack, private readonly Stopwatch $stopwatch, private readonly bool $cliMode, - private readonly UrlGeneratorInterface $urlGenerator, + private readonly ?UrlGeneratorInterface $urlGenerator = null, ) { $this->profiles = new \SplObjectStorage(); $this->parents = new \SplObjectStorage(); @@ -140,12 +140,14 @@ public function profile(ConsoleTerminateEvent $event): void $p = $this->profiles[$r]; $this->profiler->saveProfile($p); - $token = $p->getToken(); - $output?->writeln(sprintf( - 'See profile %s', - $this->urlGenerator->generate('_profiler', ['token' => $token], UrlGeneratorInterface::ABSOLUTE_URL), - $token - )); + if ($this->urlGenerator && $output) { + $token = $p->getToken(); + $output->writeln(sprintf( + 'See profile %s', + $this->urlGenerator->generate('_profiler', ['token' => $token], UrlGeneratorInterface::ABSOLUTE_URL), + $token + )); + } } $this->profiles = new \SplObjectStorage(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php index d863cd8b1db7e..eaef795977d98 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.php @@ -44,7 +44,7 @@ service('.virtual_request_stack'), service('debug.stopwatch'), param('kernel.runtime_mode.cli'), - service('router'), + service('router')->nullOnInvalid(), ]) ->tag('kernel.event_subscriber')