如何调试symfony2服务容器中配置的标签和服务? [英] How to debug tags and services configured in the symfony2 service container?

查看:152
本文介绍了如何调试symfony2服务容器中配置的标签和服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个服务来处理AccessDeniedException,我发现一种方法可以从使用Symfony2的AccessDeniedHandlerInterface

 防火墙:
secured_area:
.....
access_denied_handler:内核。 listener.accessDenied.handler

在此定义服务:

  services:
kernel.listener.accessDenied.handler:
class:%kernel.listener.accessDenied.handler.class%
arguments :[@service_container]
标签:
- {name:'kernel.event_listener',event:'security.kernel_response',方法:'handle'}

但我不知道在哪里可以找到这些属性的定义,例如 event:'security.kernel_response'。在哪里定义了'security.kernel_response',在哪里可以获取其他事件的列表?



对于像access_denied_handler这样的其他处理程序,我如何确定标签对于相应的服务?

解决方案

调试Symfony容器



要调试服务容器,请使用以下控制台命令之一



当前版本(> 2.7)



显示所有注册服务



 应用程序/控制台调试:容器



按标签排序的列表



  app / console debug:container --tags 



由单个标签过滤(即表单.type)



  app / console debug:container --tag = form.type 



并包含私人服务



 控制台调试:container --show-private 




版本> 2.2到< 2.7



显示所有注册的服务



  app / console container:debug 



按标签排序的列表



  app / console container:debug --tags 



由单个标签过滤(即form.type)



  app / console container:debug --tag = form.type 



并包含私人服务



  app / console container:debug --show-private 




版本< 2.2



要快速找到服务/标签(或者在symfony2上标记的服务。< 2)使用 grep (linux,osx)或 findstr (windows)这样一条管道:

  app / console container:debug | grep form 

  app / console container:debug | findstr form 


I am writing a service to handle AccessDeniedException and I found a way to solve it from Using Symfony2's AccessDeniedHandlerInterface

 firewalls:
         secured_area:
         .....
            access_denied_handler: kernel.listener.accessDenied.handler

And define the service here:

services:
    kernel.listener.accessDenied.handler:
      class: %kernel.listener.accessDenied.handler.class%
      arguments: ["@service_container"]
      tags:
            - { name: 'kernel.event_listener', event: 'security.kernel_response', method: 'handle' }

But I dont know where I can find the definitions of these attributes for example event: 'security.kernel_response' . Where is the 'security.kernel_response' defined and where I can get the list of other events?

And for other handlers like 'access_denied_handler', how can I determine the tags for the corresponding services?

解决方案

Debugging the Symfony container:

To debug the service container please use one of the following console commands

Current versions (> 2.7)

Show all registered services

app/console debug:container

List ordered by tags

app/console debug:container --tags

Filtered by a single tag ( i.e. form.type )

app/console debug:container --tag=form.type

and to include private services

app/console debug:container --show-private


Versions > 2.2 to < 2.7

Show all registered services

app/console container:debug

List ordered by tags

app/console container:debug --tags

Filtered by a single tag ( i.e. form.type )

app/console container:debug --tag=form.type

and to include private services

app/console container:debug --show-private


Versions < 2.2

To quickly find a service / tag (or tagged services on symfony2.<2) use grep ( linux, osx ) or findstr ( windows ) with a pipe like this:

app/console container:debug | grep form

or

app/console container:debug | findstr form

这篇关于如何调试symfony2服务容器中配置的标签和服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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