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
Copy file name to clipboardExpand all lines: profiler/data_collector.rst
+25-12Lines changed: 25 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -104,18 +104,25 @@ The information collected by your data collector can be displayed both in the
104
104
web debug toolbar and in the web profiler. To do so, you need to create a Twig
105
105
template that includes some specific blocks.
106
106
107
-
However, first you must add some getters in the data collector class to give the
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
108
110
template access to the collected information::
109
111
110
112
// src/DataCollector/RequestCollector.php
111
113
namespace App\DataCollector;
112
114
113
-
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
115
+
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
114
116
115
-
class RequestCollector extends DataCollector
117
+
class RequestCollector extends AbstractDataCollector
116
118
{
117
119
// ...
118
120
121
+
public static function getTemplate(): ?string
122
+
{
123
+
return 'data_collector/template.html.twig';
124
+
}
125
+
119
126
public function getMethod()
120
127
{
121
128
return $this->data['method'];
@@ -227,8 +234,9 @@ The ``menu`` and ``panel`` blocks are the only required blocks to define the
227
234
contents displayed in the web profiler panel associated with this data collector.
228
235
All blocks have access to the ``collector`` object.
229
236
230
-
Finally, to enable the data collector template, override your service configuration
231
-
to specify a tag that contains the template:
237
+
That's it ! Your data collector is now accessible in the toolbar.
238
+
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:
232
240
233
241
.. configuration-block::
234
242
@@ -240,9 +248,8 @@ to specify a tag that contains the template:
240
248
tags:
241
249
-
242
250
name: data_collector
243
-
template: 'data_collector/template.html.twig'
244
251
# must match the value returned by the getName() method
245
-
id: 'app.request_collector'
252
+
id: 'App\DataCollector\RequestCollector'
246
253
# optional priority
247
254
# priority: 300
248
255
@@ -259,8 +266,7 @@ to specify a tag that contains the template:
259
266
<serviceid="App\DataCollector\RequestCollector">
260
267
<!-- priority="300" -->
261
268
<tagname="data_collector"
262
-
template="data_collector/template.html.twig"
263
-
id="app.request_collector"
269
+
id="App\DataCollector\RequestCollector"
264
270
/>
265
271
</service>
266
272
</services>
@@ -277,10 +283,8 @@ to specify a tag that contains the template:
@@ -289,3 +293,12 @@ The position of each panel in the toolbar is determined by the collector priorit
289
293
Priorities are defined as positive or negative integers and they default to ``0``.
290
294
Most built-in collectors use ``255`` as their priority. If you want your collector
291
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