From 275b695d6bd1476aadfeb5951c0830b0e473b280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 24 Aug 2025 12:24:08 +0200 Subject: [PATCH] Use ajax_replace option for symfony debug toolbar instead of custom event subscriber --- config/packages/web_profiler.yaml | 3 +- .../SymfonyDebugToolbarSubscriber.php | 69 ------------------- 2 files changed, 2 insertions(+), 70 deletions(-) delete mode 100644 src/EventSubscriber/SymfonyDebugToolbarSubscriber.php diff --git a/config/packages/web_profiler.yaml b/config/packages/web_profiler.yaml index 0eac3c98..15112444 100644 --- a/config/packages/web_profiler.yaml +++ b/config/packages/web_profiler.yaml @@ -1,6 +1,7 @@ when@dev: web_profiler: - toolbar: true + toolbar: + ajax_replace: true framework: profiler: diff --git a/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php b/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php deleted file mode 100644 index 6f17e399..00000000 --- a/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php +++ /dev/null @@ -1,69 +0,0 @@ -. - */ - -declare(strict_types=1); - -namespace App\EventSubscriber; - -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\ResponseEvent; - -/** - * This subscriber sets a Header in Debug mode that signals the Symfony Profiler to also update on Ajax requests. - */ -final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface -{ - public function __construct(private readonly bool $kernel_debug_enabled) - { - } - - /** - * Returns an array of event names this subscriber wants to listen to. - * - * The array keys are event names and the value can be: - * - * * The method name to call (priority defaults to 0) - * * An array composed of the method name to call and the priority - * * An array of arrays composed of the method names to call and respective - * priorities, or 0 if unset - * - * For instance: - * - * * ['eventName' => 'methodName'] - * * ['eventName' => ['methodName', $priority]] - * * ['eventName' => [['methodName1', $priority], ['methodName2']]] - * - * @return array The event names to listen to - */ - public static function getSubscribedEvents(): array - { - return ['kernel.response' => 'onKernelResponse']; - } - - public function onKernelResponse(ResponseEvent $event): void - { - if (!$this->kernel_debug_enabled) { - return; - } - - $response = $event->getResponse(); - $response->headers->set('Symfony-Debug-Toolbar-Replace', '1'); - } -}