是否有Symfony2默认容器服务的列表? [英] Is there a list of Symfony2 default container services?

查看:100
本文介绍了是否有Symfony2默认容器服务的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以Symfony2网站为例,关于定义自定义服务(YAML符号)的示例:

 服务:
newsletter_manager:
class:%newsletter_manager.class%
参数:[@mailer,@templating]

是否有一个默认的Symfony2服务对象列表可以注入到自定义服务中作为参数(如 @邮件员 @templating @doctrine )?



我知道他们来自 Container (可以使用,例如每个 Controller class)。我尝试转储所有服务,但我正在寻找一个更详细的列表:

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

logger容器Symfony\Bridge\Monolog\Logger
邮件容器Swift_Mailer
翻译器n / a翻译器的别名
...


解决方案

命令行 php app / console container:debug 显示可以注入到另一个服务中的服务列表,或者通过Controller :: get($ serviceName)从控制器获取。 / p>

此列表仅显示 public 服务。将 - show-private 选项添加到显示私人服务中。私人服务只能注入其他服务,不能从控制器或任何ContainerAware访问...



编辑:从Symfony 2.7,使用 debug:container 而不是 container:debug


Here is an example, taken from Symfony2 website, about defining a custom service (YAML notation):

services:
    newsletter_manager:
        class:     %newsletter_manager.class%
        arguments: [@mailer, @templating]

Is there a list of default Symfony2 service objects that can be injected into a custom service as parameters (like @mailer, @templating, @doctrine)?

I know that they come from the Container (which is available, for example, in each Controller class). I've tryed to dump all services, but i'm looking for a more detailed list:

php app/console container:debug

logger container Symfony\Bridge\Monolog\Logger
mailer container Swift_Mailer
translator n/a alias for translator.default
...

解决方案

The command line php app/console container:debug shows the list of services you can inject into another service or get from a Controller with Controller::get($serviceName).

This list shows only public services. Add the option --show-private into display private services. Private services can only be injected in another service, not accessed from a Controller or any ContainerAware...

EDIT: From Symfony 2.7, use debug:container instead of container:debug

这篇关于是否有Symfony2默认容器服务的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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