2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-07-09 09:05:26 +01:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Console;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2013-08-09 13:53:54 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Console\Application as BaseApplication;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2011-01-25 16:20:20 +00:00
|
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
2010-09-15 19:49:16 +01:00
|
|
|
use Symfony\Component\HttpKernel\Kernel;
|
2012-08-03 10:50:44 +01:00
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-04-07 01:51:29 +01:00
|
|
|
* Application.
|
2010-02-28 16:55:29 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:55:05 +00:00
|
|
|
*/
|
|
|
|
class Application extends BaseApplication
|
|
|
|
{
|
2011-03-11 11:53:42 +00:00
|
|
|
private $kernel;
|
2013-06-10 14:35:49 +01:00
|
|
|
private $commandsRegistered = false;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
2011-04-23 16:05:44 +01:00
|
|
|
*
|
|
|
|
* @param KernelInterface $kernel A KernelInterface instance
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2011-01-25 16:20:20 +00:00
|
|
|
public function __construct(KernelInterface $kernel)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
|
|
|
$this->kernel = $kernel;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2011-02-07 02:03:02 +00:00
|
|
|
parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : ''));
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2011-11-20 11:56:56 +00:00
|
|
|
$this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment()));
|
2011-03-11 15:02:03 +00:00
|
|
|
$this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Gets the Kernel associated with this Console.
|
|
|
|
*
|
2011-01-25 16:20:20 +00:00
|
|
|
* @return KernelInterface A KernelInterface instance
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getKernel()
|
|
|
|
{
|
|
|
|
return $this->kernel;
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Runs the current application.
|
|
|
|
*
|
|
|
|
* @param InputInterface $input An Input instance
|
|
|
|
* @param OutputInterface $output An Output instance
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @return int 0 if everything went fine, or an error code
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function doRun(InputInterface $input, OutputInterface $output)
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2013-07-29 18:21:16 +01:00
|
|
|
$this->kernel->boot();
|
|
|
|
|
|
|
|
$container = $this->kernel->getContainer();
|
|
|
|
|
|
|
|
foreach ($this->all() as $command) {
|
2013-08-09 13:53:54 +01:00
|
|
|
if ($command instanceof ContainerAwareInterface) {
|
2013-07-29 18:21:16 +01:00
|
|
|
$command->setContainer($container);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setDispatcher($container->get('event_dispatcher'));
|
2013-05-28 20:38:03 +01:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
return parent::doRun($input, $output);
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2016-01-27 12:18:03 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function get($name)
|
|
|
|
{
|
|
|
|
$this->registerCommands();
|
|
|
|
|
|
|
|
return parent::get($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function all($namespace = null)
|
|
|
|
{
|
|
|
|
$this->registerCommands();
|
|
|
|
|
|
|
|
return parent::all($namespace);
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
protected function registerCommands()
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2016-01-27 12:18:03 +00:00
|
|
|
if ($this->commandsRegistered) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->commandsRegistered = true;
|
|
|
|
|
2016-02-18 16:03:55 +00:00
|
|
|
$this->kernel->boot();
|
|
|
|
|
2013-09-06 09:47:41 +01:00
|
|
|
$container = $this->kernel->getContainer();
|
|
|
|
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach ($this->kernel->getBundles() as $bundle) {
|
2012-08-01 10:32:18 +01:00
|
|
|
if ($bundle instanceof Bundle) {
|
|
|
|
$bundle->registerCommands($this);
|
|
|
|
}
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2014-02-13 14:09:55 +00:00
|
|
|
|
|
|
|
if ($container->hasParameter('console.command.ids')) {
|
|
|
|
foreach ($container->getParameter('console.command.ids') as $id) {
|
|
|
|
$this->add($container->get($id));
|
|
|
|
}
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
2011-05-02 17:35:38 +01:00
|
|
|
}
|