Skip to content

Commit 7e7425c

Browse files
committed
Merge pull request #3031 from lyrixx/command-in-the-DIC
[WCM]Register Commands in the Service Container
2 parents 808319d + f98fa24 commit 7e7425c

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

cookbook/console/console_command.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,52 @@ This command will now automatically be available to run:
6262
6363
$ app/console demo:greet Fabien
6464
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+
65111
Getting Services from the Service Container
66112
-------------------------------------------
67113

reference/dic_tags.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ may also be tags in other bundles you use that aren't listed here.
2929
+-----------------------------------+---------------------------------------------------------------------------+
3030
| `assetic.templating.twig`_ | Remove this service if twig templating is disabled |
3131
+-----------------------------------+---------------------------------------------------------------------------+
32+
| `console.command`_ | Add a command |
33+
+-----------------------------------+---------------------------------------------------------------------------+
3234
| `data_collector`_ | Create a class that collects custom data for the profiler |
3335
+-----------------------------------+---------------------------------------------------------------------------+
3436
| `doctrine.event_listener`_ | Add a Doctrine event listener |
@@ -241,6 +243,18 @@ assetic.templating.twig
241243
The tagged service will be removed from the container if
242244
``framework.templating.engines`` config section does not contain twig.
243245
246+
console.command
247+
---------------
248+
249+
.. versionadded:: 2.4
250+
Support for registering commands in the service container was added in
251+
version 2.4.
252+
253+
**Purpose**: Add a command to the application
254+
255+
For details on registering your own commands in the service container, read
256+
:ref:`the cookbook article<cookbook-console-dic>`.
257+
244258
data_collector
245259
--------------
246260

0 commit comments

Comments
 (0)