vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Symfony\Bundle\FrameworkBundle\Console;
       
    13 
       
    14 use Symfony\Component\Console\Application as BaseApplication;
       
    15 use Symfony\Component\Console\Input\InputInterface;
       
    16 use Symfony\Component\Console\Input\InputOption;
       
    17 use Symfony\Component\Console\Output\OutputInterface;
       
    18 use Symfony\Component\HttpKernel\KernelInterface;
       
    19 use Symfony\Component\HttpKernel\Kernel;
       
    20 
       
    21 /**
       
    22  * Application.
       
    23  *
       
    24  * @author Fabien Potencier <fabien@symfony.com>
       
    25  */
       
    26 class Application extends BaseApplication
       
    27 {
       
    28     private $kernel;
       
    29 
       
    30     /**
       
    31      * Constructor.
       
    32      *
       
    33      * @param KernelInterface $kernel A KernelInterface instance
       
    34      */
       
    35     public function __construct(KernelInterface $kernel)
       
    36     {
       
    37         $this->kernel = $kernel;
       
    38 
       
    39         parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : ''));
       
    40 
       
    41         $this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.'));
       
    42         $this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'));
       
    43         $this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
       
    44     }
       
    45 
       
    46     /**
       
    47      * Gets the Kernel associated with this Console.
       
    48      *
       
    49      * @return KernelInterface A KernelInterface instance
       
    50      */
       
    51     public function getKernel()
       
    52     {
       
    53         return $this->kernel;
       
    54     }
       
    55 
       
    56     /**
       
    57      * Runs the current application.
       
    58      *
       
    59      * @param InputInterface  $input  An Input instance
       
    60      * @param OutputInterface $output An Output instance
       
    61      *
       
    62      * @return integer 0 if everything went fine, or an error code
       
    63      */
       
    64     public function doRun(InputInterface $input, OutputInterface $output)
       
    65     {
       
    66         $this->registerCommands();
       
    67 
       
    68         if (true === $input->hasParameterOption(array('--shell', '-s'))) {
       
    69             $shell = new Shell($this);
       
    70             $shell->run();
       
    71 
       
    72             return 0;
       
    73         }
       
    74 
       
    75         return parent::doRun($input, $output);
       
    76     }
       
    77 
       
    78     protected function registerCommands()
       
    79     {
       
    80         $this->kernel->boot();
       
    81         foreach ($this->kernel->getBundles() as $bundle) {
       
    82             $bundle->registerCommands($this);
       
    83         }
       
    84     }
       
    85 }