@@ -12,11 +12,11 @@ use it to create your own commands.
1212Creating a Command
1313------------------
1414
15- Commands are defined in classes which must be created in the ``Command `` namespace
16- of your bundle (e.g. ``AppBundle\Command ``) and their names must end with the
15+ Commands are defined in classes which should be created in the ``Command `` namespace
16+ of your bundle (e.g. ``AppBundle\Command ``) and their names should end with the
1717``Command `` suffix.
1818
19- For example, a command called `` CreateUser `` must follow this structure ::
19+ For example, you may want a command to create a user ::
2020
2121 // src/AppBundle/Command/CreateUserCommand.php
2222 namespace AppBundle\Command;
@@ -64,12 +64,28 @@ method. Then you can optionally define a help message and the
6464Executing the Command
6565---------------------
6666
67- After configuring the command, you can execute it in the terminal:
67+ Symfony registers any PHP class extending :class: `Symfony\\ Component\\ Console\\ Command\\ Command `
68+ as a console command automatically. So you can now execute this command in the
69+ terminal:
6870
6971.. code-block :: terminal
7072
7173 $ php bin/console app:create-user
7274
75+ .. note ::
76+
77+ If you're using the :ref: `default services.yml configuration <service-container-services-load-example >`,
78+ your command classes are automatically registered as services.
79+
80+ You can also manually register your command as a service by configuring the service
81+ and :doc: `tagging it </service_container/tags >` with ``console.command ``.
82+
83+ .. caution ::
84+
85+ Symfony also looks in the ``Command/ `` directory of bundles for commands
86+ non registered as a service but this is deprecated since Symfony 3.4 and
87+ won't be supported in Symfony 4.0.
88+
7389As you might expect, this command will do nothing as you didn't write any logic
7490yet. Add your own logic inside the ``execute() `` method, which has access to the
7591input stream (e.g. options and arguments) and the output stream (to write
0 commit comments