-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[WCM]Register Commands in the Service Container #3031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,52 @@ This command will now automatically be available to run: | |
|
||
$ app/console demo:greet Fabien | ||
|
||
.. _cookbook-console-dic: | ||
|
||
Register Commands in the Service Container | ||
------------------------------------------ | ||
|
||
.. versionadded:: 2.4 | ||
Support for registering commands in the service container was added in | ||
version 2.4. | ||
|
||
You can register commands in the service container using the ``console.command`` | ||
tag: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/config.yml | ||
services: | ||
acme_hello.command.my_command: | ||
class: Acme\HelloBundle\Command\MyCommand | ||
tags: | ||
- { name: console.command } | ||
|
||
.. code-block:: xml | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <!-- app/config/config.xml --> |
||
<!-- app/config/config.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<service id="acme_hello.command.my_command" | ||
class="Acme\HelloBundle\Command\MyCommand"> | ||
<tag name="console.command" /> | ||
</service> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // app/config/config.php
use Symfony\Component\DependencyInjection\Definition; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use statement not needed if you are using the alternatives |
||
// app/config/config.php | ||
|
||
$container | ||
->register('acme_hello.command.my_command', 'Acme\HelloBundle\Command\MyCommand') | ||
->addTag('console.command') | ||
; | ||
|
||
Getting Services from the Service Container | ||
------------------------------------------- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ may also be tags in other bundles you use that aren't listed here. | |
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `assetic.templating.twig`_ | Remove this service if twig templating is disabled | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `console.command`_ | Add a command | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `data_collector`_ | Create a class that collects custom data for the profiler | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `doctrine.event_listener`_ | Add a Doctrine event listener | | ||
|
@@ -241,6 +243,18 @@ assetic.templating.twig | |
The tagged service will be removed from the container if | ||
``framework.templating.engines`` config section does not contain twig. | ||
|
||
console.command | ||
--------------- | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing versionadded, after that it's ready to merge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
.. versionadded:: 2.4 | ||
Support for registering commands in the service container was added in | ||
version 2.4. | ||
|
||
**Purpose**: Add a command to the application | ||
|
||
For details on registering your own commands in the service container, read | ||
:ref:`the cookbook article<cookbook-console-dic>`. | ||
|
||
data_collector | ||
-------------- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# app/config/config.yml