@@ -12,11 +12,11 @@ use it to create your own commands.
12
12
Creating a Command
13
13
------------------
14
14
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
17
17
``Command `` suffix.
18
18
19
- For example, a command called `` CreateUser `` must follow this structure ::
19
+ For example, you may want a command to create a user ::
20
20
21
21
// src/AppBundle/Command/CreateUserCommand.php
22
22
namespace AppBundle\Command;
@@ -64,12 +64,28 @@ method. Then you can optionally define a help message and the
64
64
Executing the Command
65
65
---------------------
66
66
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:
68
70
69
71
.. code-block :: terminal
70
72
71
73
$ php bin/console app:create-user
72
74
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
+
73
89
As you might expect, this command will do nothing as you didn't write any logic
74
90
yet. Add your own logic inside the ``execute() `` method, which has access to the
75
91
input stream (e.g. options and arguments) and the output stream (to write
0 commit comments