Symfony includes numerous pre-built commands designed for debugging various components of an application. Symfony relies heavily on its service container to manage and organize various components of the application. The service container acts as a centralized hub for handling dependencies and services. However, when dealing with complex applications, debugging and understanding the services registered in the container can be challenging. This tutorial explains how to debug service container using console command in Symfony 7.
All services
The debug:container
command provides a comprehensive overview of the services registered in the Symfony application. Basic usage:
php bin/console debug:container
Running this command without any additional options will display a list of all services registered in the container. This list includes service IDs and class names. Output example:
------------------------------------ -------------------------------
Service ID Class name
------------------------------------ -------------------------------
App\Command\TestCommand App\Command\TestCommand
App\Controller\TestController App\Controller\TestController
App\Controller\TwigController App\Controller\TwigController
App\Kernel alias for "kernel"
App\Service\TestService App\Service\TestService
Psr\Cache\CacheItemPoolInterface alias for "cache.app"
Psr\Clock\ClockInterface alias for "clock"
...
Specific service
To display details of a specific service, provide its ID:
php bin/console debug:container serializer
This command will provide detailed information about the specified service, including its class, tags, and other information.
---------------- ---------------------------------------------------------------------
Option Value
---------------- ---------------------------------------------------------------------
Service ID debug.serializer
Class Symfony\Component\Serializer\Debug\TraceableSerializer
Tags container.decorator (id: serializer, inner: debug.serializer.inner)
Public no
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired no
Autoconfigured no
Service tags
Utilize the --tags
option to see publicly accessible services grouped by their respective tags:
php bin/console debug:container --tags
Output example:
"cache.pool" tag
----------------
* cache.app
* cache.system
* cache.validator
...
"cache.pool.clearer" tag
------------------------
* cache.default_clearer
* cache.system_clearer
* cache.global_clearer
...
Container parameters
Use the --parameters
option to showcase all parameters within the container:
php bin/console debug:container --parameters
Output exmaple:
---------------------------- ---------------------------------
Parameter Value
---------------------------- ---------------------------------
...
kernel.charset UTF-8
kernel.container_class App_KernelDevDebugContainer
kernel.debug true
kernel.default_locale en
kernel.enabled_locales []
kernel.environment dev
kernel.error_controller error_controller
...
Deprecations
To see deprecations generated during the compilation of the container and cache warm up, use the --deprecations
option:
php bin/console debug:container --deprecations
If continuous integration is used, recommended adding debug:container --deprecations
command to the list of commands which executed on each build.
Leave a Comment
Cancel reply