Skip to content

Commit 21884a3

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: fix tests [FrameworkBundle] Fix profiling commands without router [FrameworkBundle] Fix profiling command in web context [WebProfilerBundle] Fix Copy as Curl [SecurityBundle] Fix redeclaration of `InternalSecurity` class when opcache preload is active
2 parents 71f790c + d61db2b commit 21884a3

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

EventListener/ConsoleProfilerListener.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function __construct(
4242
private readonly Profiler $profiler,
4343
private readonly RequestStack $requestStack,
4444
private readonly Stopwatch $stopwatch,
45-
private readonly UrlGeneratorInterface $urlGenerator,
45+
private readonly bool $cliMode,
46+
private readonly ?UrlGeneratorInterface $urlGenerator = null,
4647
) {
4748
$this->profiles = new \SplObjectStorage();
4849
$this->parents = new \SplObjectStorage();
@@ -59,6 +60,10 @@ public static function getSubscribedEvents(): array
5960

6061
public function initialize(ConsoleCommandEvent $event): void
6162
{
63+
if (!$this->cliMode) {
64+
return;
65+
}
66+
6267
$input = $event->getInput();
6368
if (!$input->hasOption('profile') || !$input->getOption('profile')) {
6469
$this->profiler->disable();
@@ -78,12 +83,16 @@ public function initialize(ConsoleCommandEvent $event): void
7883

7984
public function catch(ConsoleErrorEvent $event): void
8085
{
86+
if (!$this->cliMode) {
87+
return;
88+
}
89+
8190
$this->error = $event->getError();
8291
}
8392

8493
public function profile(ConsoleTerminateEvent $event): void
8594
{
86-
if (!$this->profiler->isEnabled()) {
95+
if (!$this->cliMode || !$this->profiler->isEnabled()) {
8796
return;
8897
}
8998

@@ -131,12 +140,14 @@ public function profile(ConsoleTerminateEvent $event): void
131140
$p = $this->profiles[$r];
132141
$this->profiler->saveProfile($p);
133142

134-
$token = $p->getToken();
135-
$output?->writeln(sprintf(
136-
'See profile <href=%s>%s</>',
137-
$this->urlGenerator->generate('_profiler', ['token' => $token], UrlGeneratorInterface::ABSOLUTE_URL),
138-
$token
139-
));
143+
if ($this->urlGenerator && $output) {
144+
$token = $p->getToken();
145+
$output->writeln(sprintf(
146+
'See profile <href=%s>%s</>',
147+
$this->urlGenerator->generate('_profiler', ['token' => $token], UrlGeneratorInterface::ABSOLUTE_URL),
148+
$token
149+
));
150+
}
140151
}
141152

142153
$this->profiles = new \SplObjectStorage();

Resources/config/profiling.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
service('profiler'),
4444
service('.virtual_request_stack'),
4545
service('debug.stopwatch'),
46-
service('router'),
46+
param('kernel.runtime_mode.cli'),
47+
service('router')->nullOnInvalid(),
4748
])
4849
->tag('kernel.event_subscriber')
4950

0 commit comments

Comments
 (0)