如何停用某些 symfony2 调试工具栏元素? [英] How to deactivate some symfony2 debug toolbar elements?

查看:49
本文介绍了如何停用某些 symfony2 调试工具栏元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 symfony2,它的调试工具栏很棒.

I am using symfony2 and its debug toolbar is great.

但是,我来安装一些额外的包,这些包添加了一些元素,现在显示在两个级别上.

However, I've come to install som extra bundles which add some elements and it is now displayed on two levels.

如何从工具栏中删除一些元素?

How can I do to remove some elements from the toolbar ?

例如,我不需要有关我的 phpversion 的信息,不需要有关路线等的信息.

For example, I don't need info about my phpversion, not about the route, etc.

推荐答案

工具栏的元素被称为 DataCollector,它们是标记为 data_collector 的特殊服务.在以下几行中,我将以 Time Datacollector 为例.

Elements of the toolbar are called DataCollectors, they are special services tagged with data_collector. In the following lines, i will take the Time Datacollector as example.

因此,为了停用其中一个,您首先必须获得他的服务 ID.您可以通过运行控制台命令列出所有 DataCollectors:

So in order to deactivate one of them, you first have to get his service id. You can list all the DataCollectors by running the console command:

php console container:debug --show-private --tag='data_collector'

输出为:

[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

所以现在您获得了服务的 id,即 time,您必须构建名称.添加 data_collector. 作为 id 的前缀以获取名称.服务的名称是 data_collector.time.

So now you got the id of the service which is time, you have to build the name. Add data_collector. as a prefix of the id to get the name. The name of the service is data_collector.time.

现在你想停用它,你必须给它一个零优先级.

Now as you want to deactivate it, you have to give it a Zero priority.

在你的 config.yml 中:

In your config.yml:

services:
    data_collector.time:
        class: "%data_collector.time.class%"
        tags:
           - {name: 'data_collector', priority: '0'}    

现在分析器没有 time 了.

Now the profiler doesn't have the time no more.

这是一种使某些分析器项目无法正常运行的方法.(又名:sym​​fony 更新不会影响它,除非他们更改 DataCollector 的名称)

This is a way to unable some profiler items properly. ( A.K.A: A symfony update won't affect it, unless they change the name of the DataCollectors )

最短的方法是直接将零优先级放在vendor/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>

所有的 DataCollector 都不是在同一个文件中定义的.但这里是其中一些的快速列表:

All the DataCollectors are not defined in the same file. But here is a quick 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:

这篇关于如何停用某些 symfony2 调试工具栏元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆