Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[WebProfilerBundle] document how to disable data collector internal tracing logic#21335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
94noni wants to merge3 commits intosymfony:7.3
base:7.3
Choose a base branch
Loading
from94noni:patch-17
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletionsprofiler.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -368,6 +368,64 @@ data serialization (during :ref:`kernel.terminate <component-http-kernel-kernel-
with ``autoconfigure``, then Symfony will start using your data collector after the
next page refresh. Otherwise, :ref:`enable the data collector by hand <data_collector_tag>`.

.. warning::

It arrives that some data collector leverage some decorated underlying service (traceable service).
And as the profiler mechanism can be disabled, you may adapt your collector to handle such case
to avoid unwanted useless memory leak.
You can do so by injecting the ``profiler.is_disabled_state_checker`` service::

// src/Debug/TraceableService.php
namespace App\Debug;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class TraceableService
{
public function __construct(
private ServiceInterface $decoratedService,
protected readonly ?\Closure $disabled = null, // profiler.is_disabled_state_checker
) {}

public function action(): array
{
if ($this->disabled?->__invoke()) {
return $this->decoratedService->action();
}

// do the tracing job to gather/load/compute some data to be collected by your data collector...
return [/* heavy data */];
}
}

// src/DataCollector/ServiceCollector.php
namespace App\DataCollector;

use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ServiceCollector extends AbstractDataCollector
{
public function __construct(
private ServiceInterface $service, // here we have TraceableService
) {}

public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
$data = $this->service->action();

$this->data = [
'data' => $data,
];
}
}

.. versionadded:: 7.3

The ``profiler.is_disabled_state_checker`` service was introduced in Symfony 7.3.

Adding Web Profiler Templates
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp