Is there a list of Symfony2 default container serv

2019-01-29 23:11发布

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
...

6条回答
一纸荒年 Trace。
2楼-- · 2019-01-29 23:26

you can also do this if you want to get details of a single service:

    php app/console container:debug service_id

this will give you info on that service

查看更多
冷血范
3楼-- · 2019-01-29 23:32

you can use

    php app/console container:debug

to get a list of all available public service IDs or

    php app/console container:debug --show-private

to show both public and private service IDs

查看更多
Animai°情兽
4楼-- · 2019-01-29 23:32

You can list services with

php app/console debug:container log 

If you need more about some service you can use the help

php app/console debug:container log  --help
查看更多
时光不老,我们不散
5楼-- · 2019-01-29 23:36

The WebProfilerExtraBundle is very useful for this.

It also adds some details about routing, assetic and twig that are very helpful. As a someone learning to think in Symfony, I REALLY like this bundle.

查看更多
Explosion°爆炸
6楼-- · 2019-01-29 23:46

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

查看更多
聊天终结者
7楼-- · 2019-01-29 23:52

you can use following command to get desired service details:

php app/console container:debug | grep service_name
查看更多
登录 后发表回答