From 925609a9d97e90520f59baf782d4ea8bc8c8f22d Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 10 Oct 2016 10:42:54 +0200 Subject: [PATCH 1/3] Added an article about private console commands --- console/private_commands.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 console/private_commands.rst diff --git a/console/private_commands.rst b/console/private_commands.rst new file mode 100644 index 00000000000..a534667ad44 --- /dev/null +++ b/console/private_commands.rst @@ -0,0 +1,34 @@ +Creating Private Console Commands +================================= + +Console commands are public by default, meaning that they are listed alongside +other commands when executing the console application script without arguments +or when using the ``list`` command. + +However, sometimes commands are not intended to be executed by end-users; for +example, commands for the legacy parts of the application, commands exclusively +executed through scheduled tasks, etc. + +In those cases, you can define the command as **private** setting the +``setPublic()`` method to ``false`` in the command configuration:: + + // src/AppBundle/Command/FooCommand.php + namespace AppBundle\Command; + + use Symfony\Component\Console\Command\Command; + + class FooCommand extends Command + { + protected function configure() + { + $this + ->setName('app:foo') + // ... + ->setPublic(false) + ; + } + } + +Private commands behave the same as public commands and they can be executed as +before, but they are no longer displayed in command listings, so end-users are +not aware of their existence. From 0ff16d28f2abc968b4819812820bb0426b56f1d4 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Sat, 19 Nov 2016 17:43:48 +0100 Subject: [PATCH 2/3] Reflect renaming from private to hidden As applied in the code repository by https://github.com/symfony/symfony/pull/20266 --- console/private_commands.rst | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/console/private_commands.rst b/console/private_commands.rst index a534667ad44..159ab6dc216 100644 --- a/console/private_commands.rst +++ b/console/private_commands.rst @@ -1,16 +1,15 @@ -Creating Private Console Commands -================================= +How to Hide Console Commands +============================ -Console commands are public by default, meaning that they are listed alongside -other commands when executing the console application script without arguments -or when using the ``list`` command. +By default, all console commands are listed when executing the console application +script without arguments or when using the ``list`` command. However, sometimes commands are not intended to be executed by end-users; for example, commands for the legacy parts of the application, commands exclusively executed through scheduled tasks, etc. -In those cases, you can define the command as **private** setting the -``setPublic()`` method to ``false`` in the command configuration:: +In those cases, you can define the command as **hidden** by setting the +``setHidden()`` method to ``true`` in the command configuration:: // src/AppBundle/Command/FooCommand.php namespace AppBundle\Command; @@ -23,12 +22,11 @@ In those cases, you can define the command as **private** setting the { $this ->setName('app:foo') + ->setHidden(true) // ... - ->setPublic(false) ; } } -Private commands behave the same as public commands and they can be executed as -before, but they are no longer displayed in command listings, so end-users are -not aware of their existence. +Hidden commands behave the same as normal commands but they are no longer displayed +in command listings, so end-users are not aware of their existence. From ad22aede3fac70e555776e1f8974865dbecf946e Mon Sep 17 00:00:00 2001 From: Wouter J Date: Sat, 19 Nov 2016 17:46:19 +0100 Subject: [PATCH 3/3] Reflect private to hidden renaming in the file name --- console/{private_commands.rst => hide_commands.rst} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename console/{private_commands.rst => hide_commands.rst} (88%) diff --git a/console/private_commands.rst b/console/hide_commands.rst similarity index 88% rename from console/private_commands.rst rename to console/hide_commands.rst index 159ab6dc216..8c12bc49f15 100644 --- a/console/private_commands.rst +++ b/console/hide_commands.rst @@ -11,17 +11,17 @@ executed through scheduled tasks, etc. In those cases, you can define the command as **hidden** by setting the ``setHidden()`` method to ``true`` in the command configuration:: - // src/AppBundle/Command/FooCommand.php + // src/AppBundle/Command/LegacyCommand.php namespace AppBundle\Command; use Symfony\Component\Console\Command\Command; - class FooCommand extends Command + class LegacyCommand extends Command { protected function configure() { $this - ->setName('app:foo') + ->setName('app:legacy') ->setHidden(true) // ... ;