Skip to content

[Console] add documentation for kernel-aware console applications #7296

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
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
31 changes: 31 additions & 0 deletions components/console/single_command_tool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,34 @@ Of course, you can still register a command as usual::

$application->setDefaultCommand($command->getName(), true);
$application->run();

If you need to create a kernel-aware application, you can use
``Symfony\Bundle\FrameworkBundle\Console\Application`` instead of ``Symfony\Component\Console\Application``::

#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use Acme\Command\DefaultCommand;

$kernel = new AppKernel('dev', true);
$application = new Application($kernel);
$command = new DefaultCommand();

$application->add($command);

$application->setDefaultCommand($command->getName(), true);
$application->run();

.. note::
An instance of ``Symfony\Bundle\FrameworkBundle\Console\Application`` will automatically
load all default commands. If you want to change this behaviour, you can pass ``false``
as the second argument when creating the object::

$application = new Application($kernel, false);