@@ -368,6 +368,38 @@ data serialization (during :ref:`kernel.terminate <component-http-kernel-kernel-
368
368
with ``autoconfigure ``, then Symfony will start using your data collector after the
369
369
next page refresh. Otherwise, :ref: `enable the data collector by hand <data_collector_tag >`.
370
370
371
+ .. warning ::
372
+
373
+ It arrives that some data collector leverage some decorated underlying service (traceable service).
374
+ And as the profiler mechanism can be disabled, you may adapt your collector to handle such case
375
+ to avoid unwanted useless memory leak.
376
+ You can do so by injecting the ``profiler.is_disabled_state_checker `` service::
377
+
378
+ // src/DataCollector/ServiceCollector.php
379
+ namespace App\D ataCollector;
380
+
381
+ use Symfony\B undle\F rameworkBundle\D ataCollector\A bstractDataCollector;
382
+ use Symfony\C omponent\H ttpFoundation\R equest;
383
+ use Symfony\C omponent\H ttpFoundation\R esponse;
384
+
385
+ class ServiceCollector extends AbstractDataCollector
386
+ {
387
+ public function __construct(
388
+ private ServiceInterface $decoratedService,
389
+ protected readonly ?\C losure $disabled = null, // profiler.is_disabled_state_checker
390
+ ) {}
391
+
392
+ public function action(): void
393
+ {
394
+ if ($this->disabled?->__invoke()) {
395
+ return $this->decoratedService->action();
396
+ }
397
+
398
+ // do the trace job to have some data to be collected by your data collector.
399
+ }
400
+ }
401
+
402
+
371
403
Adding Web Profiler Templates
372
404
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
373
405
0 commit comments