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

Appearance settings

Commit 925609a

Browse filesBrowse files
committed
Added an article about private console commands
1 parent 2b027a9 commit 925609a
Copy full SHA for 925609a

File tree

Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed

‎console/private_commands.rst

Copy file name to clipboard
+34Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.