-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProfilerSubscriber.php
43 lines (35 loc) · 1.04 KB
/
ProfilerSubscriber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace App;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
/**
* Can be deleted with Symfony 7.3, see https://github.com/symfony/symfony/pull/59123.
*/
final class ProfilerSubscriber implements EventSubscriberInterface
{
public function __construct(
#[Autowire('kernel.debug')]
private readonly bool $debug,
) {
}
public static function getSubscribedEvents(): array
{
return [
ResponseEvent::class => 'onKernelResponse',
];
}
public function onKernelResponse(ResponseEvent $event): void
{
if (!$this->debug && !$event->isMainRequest()) {
return;
}
$request = $event->getRequest();
if (!$request->isXmlHttpRequest()) {
return;
}
$response = $event->getResponse();
$response->headers->set('Symfony-Debug-Toolbar-Replace', '1');
}
}