Skip to content

Commit 2092802

Browse files
committed
Added an article about private console commands
1 parent ff3db55 commit 2092802

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

console/private_commands.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Creating Private Console Commands
2+
=================================
3+
4+
Console commands are public by default, meaning that they are listed alongside
5+
other commands when executing the console application script without arguments
6+
or when using the ``list`` command.
7+
8+
However, sometimes commands are not intended to be executed by end-users; for
9+
example, commands for the legacy parts of the application, commands exclusively
10+
executed through scheduled tasks, etc.
11+
12+
In those cases, you can define the command as **private** setting the
13+
``setPublic()`` method to ``false`` in the command configuration::
14+
15+
// src/AppBundle/Command/FooCommand.php
16+
namespace AppBundle\Command;
17+
18+
use Symfony\Component\Console\Command\Command;
19+
20+
class FooCommand extends Command
21+
{
22+
protected function configure()
23+
{
24+
$this
25+
->setName('app:foo')
26+
// ...
27+
->setPublic(false)
28+
;
29+
}
30+
}
31+
32+
Private commands behave the same as public commands and they can be executed as
33+
before, but they are no longer displayed in command listings, so end-users are
34+
not aware of their existence.

0 commit comments

Comments
 (0)