Skip to content

Added an article about private console commands #7052

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
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
Next Next commit
Added an article about private console commands
  • Loading branch information
javiereguiluz committed Oct 10, 2016
commit 925609a9d97e90520f59baf782d4ea8bc8c8f22d
34 changes: 34 additions & 0 deletions console/private_commands.rst
Original file line number Diff line number Diff line change
@@ -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.