Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
GuilhemN wants to merge4 commits intosymfony:3.4fromGuilhemN:commands
Closed
Show file tree
Hide file tree
Changes fromall commits
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
24 changes: 20 additions & 4 deletionsconsole.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,11 +12,11 @@ use it to create your own commands.
Creating a Command
------------------

Commands are defined in classes whichmust be created in the ``Command`` namespace
of your bundle (e.g. ``AppBundle\Command``) and their namesmust end with the
Commands are defined in classes whichshould be created in the ``Command`` namespace
of your bundle (e.g. ``AppBundle\Command``) and their namesshould end with the
``Command`` suffix.

For example,a command called ``CreateUser`` must follow this structure::
For example,you may want a command to create a user::

// src/AppBundle/Command/CreateUserCommand.php
namespace AppBundle\Command;
Expand DownExpand Up@@ -64,12 +64,28 @@ 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 :class:`Symfony\\Component\\Console\\Command\\Command`
as a console command automatically. So you can now execute this command in the
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``.

.. caution::

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.

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
Expand Down
10 changes: 7 additions & 3 deletionsconsole/commands_as_services.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp