跳到内容

如何调试服务容器和列出服务

编辑此页

你可以使用控制台来查找哪些服务注册到了容器中。要显示所有服务(公共和私有)及其 PHP 类,请运行

1
2
3
4
$ php bin/console debug:container

# add this option to display "hidden services" too (those whose ID starts with a dot)
$ php bin/console debug:container --show-hidden

要查看可用于自动装配的所有可用类型列表,请运行

1
$ php bin/console debug:autowiring

调试服务标签

运行以下命令以查找哪些服务被标记了特定的标签

1
$ php bin/console debug:container --tag=kernel.event_listener

也支持部分搜索

1
2
3
4
5
6
7
8
9
10
$ php bin/console debug:container --tag=kernel

Select one of the following tags to display its information:
 [0] kernel.event_listener
 [1] kernel.event_subscriber
 [2] kernel.reset
 [3] kernel.cache_warmer
 [4] kernel.locale_aware
 [5] kernel.fragment_renderer
 [6] kernel.cache_clearer

关于单个服务的详细信息

你可以通过指定服务的 ID 来获取关于特定服务的更详细信息

1
2
3
4
$ php bin/console debug:container App\Service\Mailer

# to show the service arguments:
$ php bin/console debug:container App\Service\Mailer --show-arguments
本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议授权。
目录
    版本