You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and define the ``lateCollect()`` method, which is invoked right before the profiler
86
82
data serialization (during :ref:`kernel.terminate <component-http-kernel-kernel-terminate>` event).
87
83
88
-
.. _data_collector_tag:
89
-
90
-
Enabling Custom Data Collectors
91
-
-------------------------------
92
-
93
-
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`
94
-
with ``autoconfigure``, then Symfony will automatically see your new data collector!
95
-
Your ``collect()`` method should be called next time your refresh.
84
+
.. note::
96
85
97
-
If you're not using ``autoconfigure``, you can also :ref:`manually wire your service <services-explicitly-configure-wire-services>`
98
-
and :doc:`tag </service_container/tags>` it with ``data_collector``.
86
+
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`
87
+
with ``autoconfigure``, then Symfony will start using your data collector after the
88
+
next page refresh. Otherwise, :ref:`enable the data collector by hand <data_collector_tag>`.
99
89
100
90
Adding Web Profiler Templates
101
91
-----------------------------
@@ -104,10 +94,9 @@ The information collected by your data collector can be displayed both in the
104
94
web debug toolbar and in the web profiler. To do so, you need to create a Twig
105
95
template that includes some specific blocks.
106
96
107
-
However, first make your DataCollector to extends :class:`Symfony\\Bundle\\FrameworkBundle\\DataCollector\\AbstractDataCollector` instead of :class:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollector`. When extending :class:`Symfony\\Bundle\\FrameworkBundle\\DataCollector\\AbstractDataCollector`, you don't need to implement `getName` method; your collector FQDN is returned as identifier (you can also override it if needed). Though you need to implement `getTemplate` with the template you're going to use in the profiler (see below).
108
-
109
-
Then you must add some getters in the data collector class to give the
110
-
template access to the collected information::
97
+
First, add the ``getTemplate()`` method in your data collector class to return
98
+
the path of the Twig template to use. Then, add some *getters* to give the
99
+
template access to the collected information::::
111
100
112
101
// src/DataCollector/RequestCollector.php
113
102
namespace App\DataCollector;
@@ -140,6 +129,7 @@ block and set the value of two variables called ``icon`` and ``text``:
@@ -234,9 +225,25 @@ The ``menu`` and ``panel`` blocks are the only required blocks to define the
234
225
contents displayed in the web profiler panel associated with this data collector.
235
226
All blocks have access to the ``collector`` object.
236
227
237
-
That's it ! Your data collector is now accessible in the toolbar.
228
+
.. note::
229
+
230
+
The position of each panel in the toolbar is determined by the collector
231
+
priority, which can only be defined when :ref:`configuring the data collector by hand <data_collector_tag>`.
232
+
233
+
.. note::
234
+
235
+
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`
236
+
with ``autoconfigure``, then Symfony will start displaying your collector data
237
+
in the toolbar after the next page refresh. Otherwise, :ref:`enable the data collector by hand <data_collector_tag>`.
238
+
239
+
.. _data_collector_tag:
240
+
241
+
Enabling Custom Data Collectors
242
+
-------------------------------
238
243
239
-
If you don't use the default configuration with :ref:`autowire and autoconfigure <service-container-services-load-example>`, you'll need to configure the data collector explicitely:
244
+
If you don't use Symfony's default configuration with
245
+
:ref:`autowire and autoconfigure <service-container-services-load-example>`
246
+
you'll need to configure the data collector explicitly:
240
247
241
248
.. configuration-block::
242
249
@@ -247,10 +254,12 @@ If you don't use the default configuration with :ref:`autowire and autoconfigure
247
254
App\DataCollector\RequestCollector:
248
255
tags:
249
256
-
250
-
name: data_collector
257
+
name: data_collector
251
258
# must match the value returned by the getName() method
252
-
id: 'App\DataCollector\RequestCollector'
253
-
# optional priority
259
+
id: 'App\DataCollector\RequestCollector'
260
+
# optional template (it has more priority than the value returned by getTemplate())
261
+
template: 'data_collector/template.html.twig'
262
+
# optional priority (positive or negative integer; default = 0)
254
263
# priority: 300
255
264
256
265
.. code-block:: xml
@@ -264,10 +273,13 @@ If you don't use the default configuration with :ref:`autowire and autoconfigure
264
273
265
274
<services>
266
275
<serviceid="App\DataCollector\RequestCollector">
267
-
<!-- priority="300"-->
276
+
<!--the 'template' attribute has more priority than the value returned by getTemplate()-->
// optional priority (positive or negative integer; default = 0)
288
303
// 'priority' => 300,
289
304
]);
290
305
};
291
-
292
-
The position of each panel in the toolbar is determined by the collector priority.
293
-
Priorities are defined as positive or negative integers and they default to ``0``.
294
-
Most built-in collectors use ``255`` as their priority. If you want your collector
295
-
to be displayed before them, use a higher value (like 300).
296
-
297
-
.. versionadded:: 5.2
298
-
299
-
:class:`Symfony\\Bundle\\FrameworkBundle\\DataCollector\\AbstractDataCollector` was introduced in Symfony 5.2.
300
-
301
-
.. note::
302
-
303
-
Before the introduction of :class:`Symfony\\Bundle\\FrameworkBundle\\DataCollector\\AbstractDataCollector`, template path was defined in the service configuration (`template` key). This is still possible to define the template in the service configuration. In this case **template in service configuration takes precedence over template defined in data collector code**.
0 commit comments