From 8720124c8bbe472b2e5ec6a6034e8d0edea0f19c Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Wed, 9 Aug 2017 19:54:24 +0200 Subject: [PATCH 1/4] [Console] Commands auto-registration is deprecated --- console.rst | 19 ++++++++++++++++--- console/commands_as_services.rst | 10 +++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/console.rst b/console.rst index 37af8d1b040..b94cf484e15 100644 --- a/console.rst +++ b/console.rst @@ -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; @@ -38,6 +38,19 @@ For example, a command called ``CreateUser`` must follow this structure:: } } +If you're using the :ref:`default services.yml configuration `, +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 ` 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 ----------------------- diff --git a/console/commands_as_services.rst b/console/commands_as_services.rst index 4a51788de78..8edb22e36d2 100644 --- a/console/commands_as_services.rst +++ b/console/commands_as_services.rst @@ -5,9 +5,13 @@ How to Define Commands as Services ================================== If you're using the :ref:`default services.yml configuration `, -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:: From b8859fc4e4b6777a9f895540cb885729e1803217 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Thu, 10 Aug 2017 19:35:45 +0200 Subject: [PATCH 2/4] Fix --- console.rst | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/console.rst b/console.rst index b94cf484e15..2d2e41504ab 100644 --- a/console.rst +++ b/console.rst @@ -38,19 +38,6 @@ For example, you may want a command to create an user:: } } -If you're using the :ref:`default services.yml configuration `, -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 ` 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 ----------------------- @@ -77,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 +terminal: .. code-block:: terminal $ php bin/console app:create-user +.. note:: + + If you're using the :ref:`default services.yml configuration `, + 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 ` 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. + 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 From 0ef5f63d3f6ee83cdfc980048bd7db0387d2d16f Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Fri, 11 Aug 2017 13:00:07 +0200 Subject: [PATCH 3/4] Fix --- console.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/console.rst b/console.rst index 2d2e41504ab..cb57a49093e 100644 --- a/console.rst +++ b/console.rst @@ -64,8 +64,8 @@ method. Then you can optionally define a help message and the Executing the Command --------------------- -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 +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 @@ -80,7 +80,9 @@ terminal: You can also manually register your command as a service by configuring the service and :doc:`tagging it ` with ``console.command``. - Otherwise, Symfony looks in the ``Command/`` directory of bundles for commands +.. 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. From cd5ad47be2f3e70b5670dbb3555ecbcc8418f11c Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Mon, 14 Aug 2017 15:36:17 +0200 Subject: [PATCH 4/4] Fix grammar --- console.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console.rst b/console.rst index cb57a49093e..abab6f6c8bf 100644 --- a/console.rst +++ b/console.rst @@ -16,7 +16,7 @@ Commands are defined in classes which should be created in the ``Command`` names of your bundle (e.g. ``AppBundle\Command``) and their names should end with the ``Command`` suffix. -For example, you may want a command to create an user:: +For example, you may want a command to create a user:: // src/AppBundle/Command/CreateUserCommand.php namespace AppBundle\Command; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy