Skip to content

Commit c0fc671

Browse files
committed
minor #17809 Update "Web debug toolbar" profiler docs (florimondmanca)
This PR was merged into the 5.4 branch. Discussion ---------- Update "Web debug toolbar" profiler docs Hello, I believe I encountered the situation than symfony/symfony#42439 The current [docs](https://symfony.com/doc/current/profiler.html#updating-the-web-debug-toolbar-after-ajax-requests) on updating the Web debug toolbar after XHR requests suggest to use `$event->getKernel()->isDebug()`. I am using Symfony 6.2, and this results in an attribute error on `isDebug()`. This seems to be because `getKernel()` returns an object that implements `HttpKernelInterface`, which does not define `isDebug()`. However, this method is available on `KernelInterace`. I was able to get the intended behavior by injecting the kernel via the constructor, as shown in this documentation update proposal. I checked as follows: * Run the app with `APP_ENV=dev`. The toolbar shows up and I can see `Symfony-Debug-Toolbar-Replace: 1` in the XHR requests (I'm using [Turbo Frames](https://turbo.hotwired.dev/handbook/frames)) * Run with `APP_ENV=prod`. The toolbar doesn't show up, _and_ I cannot see `Symfony-Debug-Toolbar-Replace: 1` in the XHR requests anymore. I am targeting `5.4` as the base branch as per the contribution guidelines, given that it should be possible to inject the `KernelInterface` in Symfony 5.4 as well. Commits ------- e8cc35d Update "Web debug toolbar" profiler docs
2 parents 6c97ce4 + e8cc35d commit c0fc671

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

profiler.rst

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,35 @@ production. To do that, create an :doc:`event subscriber </event_dispatcher>`
193193
and listen to the :ref:`kernel.response <component-http-kernel-kernel-response>`
194194
event::
195195

196+
197+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
196198
use Symfony\Component\HttpKernel\Event\ResponseEvent;
199+
use Symfony\Component\HttpKernel\KernelInterface;
197200

198201
// ...
199-
200-
public function onKernelResponse(ResponseEvent $event)
201-
{
202-
if (!$event->getKernel()->isDebug()) {
203-
return;
202+
203+
class MySubscriber implements EventSubscriberInterface {
204+
public function __construct(
205+
private KernelInterface $kernel,
206+
) {
204207
}
208+
209+
// ...
205210

206-
$request = $event->getRequest();
207-
if (!$request->isXmlHttpRequest()) {
208-
return;
209-
}
211+
public function onKernelResponse(ResponseEvent $event)
212+
{
213+
if (!$this->kernel->isDebug()) {
214+
return;
215+
}
210216

211-
$response = $event->getResponse();
212-
$response->headers->set('Symfony-Debug-Toolbar-Replace', 1);
217+
$request = $event->getRequest();
218+
if (!$request->isXmlHttpRequest()) {
219+
return;
220+
}
221+
222+
$response = $event->getResponse();
223+
$response->headers->set('Symfony-Debug-Toolbar-Replace', 1);
224+
}
213225
}
214226

215227
.. index::

0 commit comments

Comments
 (0)