-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Console] Commands auto-registration is deprecated #8269
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 2 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 |
---|---|---|
|
@@ -12,11 +12,11 @@ use it to create your own commands. | |
Creating a Command | ||
------------------ | ||
|
||
Commands are defined in classes which must be created in the ``Command`` namespace | ||
of your bundle (e.g. ``AppBundle\Command``) and their names must end with the | ||
Commands are defined in classes which should be created in the ``Command`` namespace | ||
of your bundle (e.g. ``AppBundle\Command``) and their names should end with the | ||
``Command`` suffix. | ||
|
||
For example, a command called ``CreateUser`` must follow this structure:: | ||
For example, you may want a command to create an user:: | ||
|
||
// src/AppBundle/Command/CreateUserCommand.php | ||
namespace AppBundle\Command; | ||
|
@@ -64,12 +64,26 @@ method. Then you can optionally define a help message and the | |
Executing the Command | ||
--------------------- | ||
|
||
After configuring the command, you can execute it in the terminal: | ||
Symfony registers any PHP class extending from :class:`Symfony\\Component\\Console\\Command\\Command` | ||
as a console command automatically, so you can now execute this command in the | ||
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. [...] automatically. So you [...] |
||
terminal: | ||
|
||
.. code-block:: terminal | ||
|
||
$ php bin/console app:create-user | ||
|
||
.. note:: | ||
|
||
If you're using the :ref:`default services.yml configuration <service-container-services-load-example>`, | ||
your command classes are automatically registered as services. | ||
|
||
You can also manually register your command as a service by configuring the service | ||
and :doc:`tagging it </service_container/tags>` with ``console.command``. | ||
|
||
Otherwise, Symfony looks in the ``Command/`` directory of bundles for commands | ||
non registered as a service but this is deprecated since Symfony 3.4 and | ||
won't be supported in Symfony 4.0. | ||
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. Maybe we should move this whole paragraph into a 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 |
||
|
||
As you might expect, this command will do nothing as you didn't write any logic | ||
yet. Add your own logic inside the ``execute()`` method, which has access to the | ||
input stream (e.g. options and arguments) and the output stream (to write | ||
|
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.
from