Skip to content

Add helpful remarks on custom DataCollector #7773

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 3 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
11 changes: 11 additions & 0 deletions profiler/data_collector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ The
:method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::collect`
method is responsible for storing the collected data in local properties.

.. caution::

The :method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::collect` method is only called once.
It is not used to "gather" data but is there to "pick up" the data that has been stored by your service.

Most of the time, it is convenient to extend
:class:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollector` and
populate the ``$this->data`` property (it takes care of serializing the
Expand Down Expand Up @@ -71,6 +76,12 @@ collects the method and accepted content types from the request::

The getters are added to give the template access to the collected information.

.. caution::

If the data that is not directly related to the request or response, you need to make the data accessible to your DataCollector.
This can be achieved by injecting the service into your DataCollector.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can be a bit more specific what we mean with "the service" (something like "by injecting a service that provides this information into your data collector).



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one blank line is enough here

.. caution::

As the profiler serializes data collector instances, you should not
Expand Down