Is there a list of Symfony2 default container services?

SymfonyDependency Injection

Symfony Problem Overview


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

Symfony Solutions


Solution 1 - Symfony

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

Solution 2 - Symfony

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.

Solution 3 - Symfony

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

Solution 4 - Symfony

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

Solution 5 - Symfony

you can use following command to get desired service details:

php app/console container:debug | grep service_name

Solution 6 - Symfony

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPolmoninoView Question on Stackoverflow
Solution 1 - SymfonyAlterPHPView Answer on Stackoverflow
Solution 2 - SymfonyIcode4foodView Answer on Stackoverflow
Solution 3 - SymfonyVictor OdiahView Answer on Stackoverflow
Solution 4 - SymfonyVictor OdiahView Answer on Stackoverflow
Solution 5 - SymfonyAshish AwasthiView Answer on Stackoverflow
Solution 6 - SymfonyCristianView Answer on Stackoverflow