Skip to content

[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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +38,19 @@ For example, a command called ``CreateUser`` must follow this structure::
}
}

If you're using the :ref:`default services.yml configuration <service-container-services-load-example>`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that this is the Console article, this explanation about services may be a bit advanced and/or confusing. Imagine you are a user reading the article: you just want to create and run some commands. You don't even need to know what a service is.

So, why don't we reword the first paragraph to tell the user something like this:

Symfony registers any PHP class extending from Command as a console command automatically, so you can now execute this command as ........

And keep the mention of services and tags for the .. note.

Copy link
Contributor Author

@GuilhemN GuilhemN Aug 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea! However I'm not sure I did exactly what you wanted, can you check?

your command classes are automatically registered as services. You have nothing
else to do!

.. note::

You can also manually register your command as a service by configuring the service
and :doc:`tagging it </service_container/tags>` with ``console.command``.

Symfony also 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.

Configuring the Command
-----------------------

Expand Down
10 changes: 7 additions & 3 deletions console/commands_as_services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ How to Define Commands as Services
==================================

If you're using the :ref:`default services.yml configuration <service-container-services-load-example>`,
your command classes are already registered as services. Great! This is the recommended
setup, but it's not required. Symfony also looks in the ``Command/`` directory of
each bundle and automatically registers those classes as commands.
your command classes are already registered as services. Great! This is the
recommended setup.

Symfony also looks in the ``Command/`` directory of each bundle for commands
non registered as a service and automatically registers those classes as
commands. However this auto-registration was deprecated in Symfony 3.4. In
Symfony 4.0, commands won't be auto-registered anymore.

.. note::

Expand Down