Skip to content

Commit e1b4f4f

Browse files
authored
Update profiler.rst
1 parent 5e22436 commit e1b4f4f

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

profiler.rst

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,30 +375,56 @@ data serialization (during :ref:`kernel.terminate <component-http-kernel-kernel-
375375
to avoid unwanted useless memory leak.
376376
You can do so by injecting the ``profiler.is_disabled_state_checker`` service::
377377

378-
// src/DataCollector/ServiceCollector.php
379-
namespace App\DataCollector;
378+
// src/Debug/TraceableService.php
379+
namespace App\Debug;
380380

381-
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
382381
use Symfony\Component\HttpFoundation\Request;
383382
use Symfony\Component\HttpFoundation\Response;
384383

385-
class ServiceCollector extends AbstractDataCollector
384+
class TraceableService
386385
{
387386
public function __construct(
388387
private ServiceInterface $decoratedService,
389388
protected readonly ?\Closure $disabled = null, // profiler.is_disabled_state_checker
390389
) {}
391390

392-
public function action(): void
391+
public function action(): array
393392
{
394393
if ($this->disabled?->__invoke()) {
395394
return $this->decoratedService->action();
396395
}
397396

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*];
399399
}
400400
}
401401

402+
// src/DataCollector/ServiceCollector.php
403+
namespace App\DataCollector;
404+
405+
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
406+
use Symfony\Component\HttpFoundation\Request;
407+
use Symfony\Component\HttpFoundation\Response;
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, ?\Throwable $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.
402428

403429
Adding Web Profiler Templates
404430
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)