How to deactivate some elements of symfony2 debug toolbar?
I am using symfony2 and its debug toolbar is great.
However, I came to install som additional packages that add some items and now they appear on two levels.
How can I do to remove some items from the toolbar?
For example, I don't need information about my phpversion, not route, etc.
source to share
Toolbar items are named DataCollectors
, these are special services with tags data_collector
. I'll take an example in the next lines Time Datacollector
.
So, to deactivate one of them, you first need to get your service ID. You can list everything DataCollectors
by running a console command:
php console container:debug --show-private --tag='data_collector'
Output:
[container] Public and private services with tag data_collector
Service ID template id priority Class name
9d48641ce55174a7d8ab08e99157426bc290884423a78a5821440d644f6a37df_5 @WebProfiler/Collector/time.html.twig time 300 Symfony\Component\HttpKernel\DataCollector\TimeDataCollector
So now you've got the service ID time
, you need to create a name. Add data_collector.
as ID prefix to get the name. Service name data_collector.time
.
Now, when you want to deactivate it, you must give it a Zero priority.
In your config.yml:
services:
data_collector.time:
class: "%data_collector.time.class%"
tags:
- {name: 'data_collector', priority: '0'}
Now the profiler no longer has time
.
This is a way of failing some of the profiler elements correctly . (AKA: symfony update won't affect it unless they change the DataCollectors name)
The shortest way is to set the priority to zero invendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="data_collector.config.class">Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector</parameter>
<parameter key="data_collector.request.class">Symfony\Component\HttpKernel\DataCollector\RequestDataCollector</parameter>
<parameter key="data_collector.exception.class">Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector</parameter>
<parameter key="data_collector.events.class">Symfony\Component\HttpKernel\DataCollector\EventDataCollector</parameter>
<parameter key="data_collector.logger.class">Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector</parameter>
<parameter key="data_collector.time.class">Symfony\Component\HttpKernel\DataCollector\TimeDataCollector</parameter>
<parameter key="data_collector.memory.class">Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector</parameter>
<parameter key="data_collector.router.class">Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector</parameter>
</parameters>
<services>
[...]
<service id="data_collector.time" class="%data_collector.time.class%" public="false">
<tag name="data_collector" template="@WebProfiler/Collector/time.html.twig" id="time" priority="0" />
<argument type="service" id="kernel" on-invalid="ignore" />
<argument type="service" id="debug.stopwatch" on-invalid="ignore" />
</service>
[..]
</services>
</container>
All DataCollectors are undefined in the same file. But here is a short list of some of them:
data_collector.config:
data_collector.request:
data_collector.router:
data_collector.security:
data_collector.logger:
data_collector.memory:
data_collector.exception:
data_collector.events:
swiftmailer.data_collector:
source to share
I have a problem with php cache. It had a CacheDataCollector which can crash symfony2 in some cases - https://github.com/php-cache/issues/issues/112 I tried the solution above (with priority 0 ) - and it didn't work , the data collector is all Symfony2 still crashed
I have no idea why priority = 0 should disable anything. You can check yourself symfony2 ProfilerPass which process tag data_collector is at https://github.com/avorobiev/symfony2/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ProfilerPass.php
So, I used a rather dirty patch intead - in my config app, I add a service with the same name, but without the data_collector tag. how
services:
cache.data_collector:
class: Cache\CacheBundle\DataCollector\CacheDataCollector
A cleaner and more stable way is to add CompilerPass which will remove the tag - https://blog.liplex.de/disable-elements-in-the-symfony-developer-toolbar-with-compilerpass/
source to share