Skip to content

Commit 610f13e

Browse files
Don't enable tracing unless the profiler is enabled
1 parent ddc2759 commit 610f13e

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

Debug/TraceableEventDispatcher.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class TraceableEventDispatcher extends BaseTraceableEventDispatcher
2525
{
2626
protected function beforeDispatch(string $eventName, object $event): void
2727
{
28+
if ($this->disabled?->__invoke()) {
29+
return;
30+
}
2831
switch ($eventName) {
2932
case KernelEvents::REQUEST:
3033
$event->getRequest()->attributes->set('_stopwatch_token', bin2hex(random_bytes(3)));
@@ -57,6 +60,9 @@ protected function beforeDispatch(string $eventName, object $event): void
5760

5861
protected function afterDispatch(string $eventName, object $event): void
5962
{
63+
if ($this->disabled?->__invoke()) {
64+
return;
65+
}
6066
switch ($eventName) {
6167
case KernelEvents::CONTROLLER_ARGUMENTS:
6268
$this->stopwatch->start('controller', 'section');

Profiler/ProfilerStateChecker.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Profiler;
13+
14+
use Psr\Container\ContainerInterface;
15+
16+
class ProfilerStateChecker
17+
{
18+
public function __construct(
19+
private ContainerInterface $container,
20+
private bool $defaultEnabled,
21+
) {
22+
}
23+
24+
public function isProfilerEnabled(): bool
25+
{
26+
return $this->container->get('profiler')?->isEnabled() ?? $this->defaultEnabled;
27+
}
28+
29+
public function isProfilerDisabled(): bool
30+
{
31+
return !$this->isProfilerEnabled();
32+
}
33+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=8.2",
2020
"symfony/deprecation-contracts": "^2.5|^3",
2121
"symfony/error-handler": "^6.4|^7.0",
22-
"symfony/event-dispatcher": "^6.4|^7.0",
22+
"symfony/event-dispatcher": "^7.3",
2323
"symfony/http-foundation": "^7.3",
2424
"symfony/polyfill-ctype": "^1.8",
2525
"psr/log": "^1|^2|^3"

0 commit comments

Comments
 (0)