Skip to content

Commit 8720124

Browse files
committed
[Console] Commands auto-registration is deprecated
1 parent d410c46 commit 8720124

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

console.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use it to create your own commands.
1212
Creating 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 an user::
2020

2121
// src/AppBundle/Command/CreateUserCommand.php
2222
namespace AppBundle\Command;
@@ -38,6 +38,19 @@ For example, a command called ``CreateUser`` must follow this structure::
3838
}
3939
}
4040

41+
If you're using the :ref:`default services.yml configuration <service-container-services-load-example>`,
42+
your command classes are automatically registered as services. You have nothing
43+
else to do!
44+
45+
.. note::
46+
47+
You can also manually register your command as a service by configuring the service
48+
and :doc:`tagging it </service_container/tags>` with ``console.command``.
49+
50+
Symfony also looks in the ``Command/`` directory of bundles for commands
51+
non registered as a service but this is deprecated since Symfony 3.4 and
52+
won't be supported in Symfony 4.0.
53+
4154
Configuring the Command
4255
-----------------------
4356

console/commands_as_services.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ How to Define Commands as Services
55
==================================
66

77
If you're using the :ref:`default services.yml configuration <service-container-services-load-example>`,
8-
your command classes are already registered as services. Great! This is the recommended
9-
setup, but it's not required. Symfony also looks in the ``Command/`` directory of
10-
each bundle and automatically registers those classes as commands.
8+
your command classes are already registered as services. Great! This is the
9+
recommended setup.
10+
11+
Symfony also looks in the ``Command/`` directory of each bundle for commands
12+
non registered as a service and automatically registers those classes as
13+
commands. However this auto-registration was deprecated in Symfony 3.4. In
14+
Symfony 4.0, commands won't be auto-registered anymore.
1115

1216
.. note::
1317

0 commit comments

Comments
 (0)