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-03-11 11:53:42 +00:00
$this -> getDefinition () -> addOption ( new InputOption ( '--shell' , '-s' , InputOption :: VALUE_NONE , 'Launch the shell.' ));
2013-02-28 21:38:52 +00:00
$this -> getDefinition () -> addOption ( new InputOption ( '--process-isolation' , null , InputOption :: VALUE_NONE , 'Launch commands from shell as a separate process.' ));
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
*
* @ return integer 0 if everything went fine , or an error code
*/
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 ();
2013-06-10 14:35:49 +01:00
if ( ! $this -> commandsRegistered ) {
$this -> registerCommands ();
2013-06-13 08:07:59 +01:00
$this -> commandsRegistered = true ;
2013-06-10 14:35:49 +01:00
}
2011-05-02 17:35:38 +01:00
2013-07-29 18:21:16 +01:00
$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-07 15:09:11 +01:00
if ( true === $input -> hasParameterOption ( array ( '--shell' , '-s' ))) {
2010-05-06 12:25:53 +01:00
$shell = new Shell ( $this );
2011-12-15 19:02:22 +00:00
$shell -> setProcessIsolation ( $input -> hasParameterOption ( array ( '--process-isolation' )));
2010-05-06 12:25:53 +01:00
$shell -> run ();
2010-02-17 13:55:05 +00:00
2010-05-06 12:25:53 +01:00
return 0 ;
}
2010-02-17 13:55:05 +00:00
2010-05-06 12:25:53 +01:00
return parent :: doRun ( $input , $output );
}
2010-02-17 13:55:05 +00:00
2010-05-06 12:25:53 +01:00
protected function registerCommands ()
2010-02-17 13:55:05 +00:00
{
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
}
2010-02-17 13:55:05 +00:00
}
2011-05-02 17:35:38 +01:00
}