Skip to content

Added an article about private console commands #7051

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
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ variables that are passed into the expression:
Behind the scenes, expressions are compiled down to raw PHP. Our example
would generate the following PHP in the cache directory::

if (rtrim($pathinfo, '/contact') === '' && (
if ($pathinfo === '/contact' && (
in_array($context->getMethod(), array(0 => "GET", 1 => "HEAD"))
&& preg_match("/firefox/i", $request->headers->get("User-Agent"))
)) {
Expand Down
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.