@@ -375,30 +375,56 @@ data serialization (during :ref:`kernel.terminate <component-http-kernel-kernel-
375
375
to avoid unwanted useless memory leak.
376
376
You can do so by injecting the ``profiler.is_disabled_state_checker `` service::
377
377
378
- // src/DataCollector/ServiceCollector .php
379
- namespace App\D ataCollector ;
378
+ // src/Debug/TraceableService .php
379
+ namespace App\D ebug ;
380
380
381
- use Symfony\B undle\F rameworkBundle\D ataCollector\A bstractDataCollector;
382
381
use Symfony\C omponent\H ttpFoundation\R equest;
383
382
use Symfony\C omponent\H ttpFoundation\R esponse;
384
383
385
- class ServiceCollector extends AbstractDataCollector
384
+ class TraceableService
386
385
{
387
386
public function __construct(
388
387
private ServiceInterface $decoratedService,
389
388
protected readonly ?\C losure $disabled = null, // profiler.is_disabled_state_checker
390
389
) {}
391
390
392
- public function action(): void
391
+ public function action(): array
393
392
{
394
393
if ($this->disabled?->__invoke()) {
395
394
return $this->decoratedService->action();
396
395
}
397
396
398
- // do the trace job to have some data to be collected by your data collector.
397
+ // do the tracing job to gather/load/compute some data to be collected by your data collector.
398
+ return [/*heavy data *];
399
399
}
400
400
}
401
401
402
+ // src/DataCollector/ServiceCollector.php
403
+ namespace App\D ataCollector;
404
+
405
+ use Symfony\B undle\F rameworkBundle\D ataCollector\A bstractDataCollector;
406
+ use Symfony\C omponent\H ttpFoundation\R equest;
407
+ use Symfony\C omponent\H ttpFoundation\R esponse;
408
+
409
+ class ServiceCollector extends AbstractDataCollector
410
+ {
411
+ public function __construct(
412
+ private ServiceInterface $service, // here we have TraceableService
413
+ ) {}
414
+
415
+ public function collect(Request $request, Response $response, ?\T hrowable $exception = null): void
416
+ {
417
+ $data = $this->service->action();
418
+
419
+ $this->data = [
420
+ 'data' => $data,
421
+ ];
422
+ }
423
+ }
424
+
425
+ .. versionadded :: 7.3
426
+
427
+ The ``profiler.is_disabled_state_checker `` service was introduced in Symfony 7.3.
402
428
403
429
Adding Web Profiler Templates
404
430
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments