@@ -62,6 +62,52 @@ This command will now automatically be available to run:
62
62
63
63
$ app/console demo:greet Fabien
64
64
65
+ .. _cookbook-console-dic :
66
+
67
+ Register Commands in the Service Container
68
+ ------------------------------------------
69
+
70
+ .. versionadded :: 2.4
71
+ Support for registering commands in the service container was added in
72
+ version 2.4.
73
+
74
+ You can register commands in the service container using the ``console.command ``
75
+ tag:
76
+
77
+ .. configuration-block ::
78
+
79
+ .. code-block :: yaml
80
+
81
+ # app/config/config.yml
82
+ services :
83
+ acme_hello.command.my_command :
84
+ class : Acme\HelloBundle\Command\MyCommand
85
+ tags :
86
+ - { name: console.command }
87
+
88
+ .. code-block :: xml
89
+
90
+ <!-- app/config/config.xml -->
91
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
92
+ <container xmlns =" http://symfony.com/schema/dic/services"
93
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
94
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
95
+
96
+ <service id =" acme_hello.command.my_command"
97
+ class =" Acme\HelloBundle\Command\MyCommand" >
98
+ <tag name =" console.command" />
99
+ </service >
100
+ </container >
101
+
102
+ .. code-block :: php
103
+
104
+ // app/config/config.php
105
+
106
+ $container
107
+ ->register('acme_hello.command.my_command', 'Acme\HelloBundle\Command\MyCommand')
108
+ ->addTag('console.command')
109
+ ;
110
+
65
111
Getting Services from the Service Container
66
112
-------------------------------------------
67
113
0 commit comments