Skip to content

Commit f8fef4a

Browse files
committed
SF 4+ does not rely on Command inheritance anymore
As stated in [UPGRADE FROM 3.x to 4.0](https://github.com/symfony/symfony/blob/master/UPGRADE-4.0.md#httpkernel), relying on convention-based commands discovery is not supported anymore. This trick will only work with bundle autoconfiguration, which is not enabled by default on many 3rd-party bundles. This means a 3rd party bundle that wants to upgrade from SF 3.4 to SF 4.0 doesn't just have to edit its `composer.json`, its commands must either be tagged with `console.command` or autoconfigured. When [struggling with this](https://stackoverflow.com/questions/49134340/symfony-4-3rd-party-bundle-commands-are-no-longer-automatically-discovered) my eyes just hit the _Symfony registers any PHP class extending Command as a console command automatically_ sentence and I didn't figure out why it didn't work.
1 parent 9b95eae commit f8fef4a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

console.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ method. Then you can optionally define a help message and the
7272
Executing the Command
7373
---------------------
7474

75-
Symfony registers any PHP class extending :class:`Symfony\\Component\\Console\\Command\\Command`
76-
as a console command automatically. So you can now execute this command in the
77-
terminal:
75+
You can now execute this command in the terminal:
7876

7977
.. code-block:: terminal
8078
8179
$ php bin/console app:create-user
8280
8381
.. note::
8482

83+
The command class must be registered as a service with the ``console.command`` tag.
84+
8585
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`,
86-
your command classes are automatically registered as services.
86+
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.
8787

88-
You can also manually register your command as a service by configuring the service
88+
Otherwise, you can manually register your command as a service by configuring the service
8989
and :doc:`tagging it </service_container/tags>` with ``console.command``.
9090

9191
As you might expect, this command will do nothing as you didn't write any logic

0 commit comments

Comments
 (0)