Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
Строк: 256
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyBundleFrameworkBundleConsole;

use 
SymfonyComponentDependencyInjectionContainerAwareInterface;
use 
SymfonyComponentConsoleApplication as BaseApplication;
use 
SymfonyComponentConsoleInputInputInterface;
use 
SymfonyComponentConsoleInputInputOption;
use 
SymfonyComponentConsoleOutputOutputInterface;
use 
SymfonyComponentHttpKernelKernelInterface;
use 
SymfonyComponentHttpKernelKernel;
use 
SymfonyComponentHttpKernelBundleBundle;

/**
 * Application.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class Application extends BaseApplication
{
    private 
$kernel;
    private 
$commandsRegistered false;

    
/**
     * Constructor.
     *
     * @param KernelInterface $kernel A KernelInterface instance
     */
    
public function __construct(KernelInterface $kernel)
    {
        
$this->kernel $kernel;

        
parent::__construct('Symfony'Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' ''));

        
$this->getDefinition()->addOption(new InputOption('--shell''-s'InputOption::VALUE_NONE'Launch the shell.'));
        
$this->getDefinition()->addOption(new InputOption('--process-isolation'nullInputOption::VALUE_NONE'Launch commands from shell as a separate process.'));
        
$this->getDefinition()->addOption(new InputOption('--env''-e'InputOption::VALUE_REQUIRED'The Environment name.'$kernel->getEnvironment()));
        
$this->getDefinition()->addOption(new InputOption('--no-debug'nullInputOption::VALUE_NONE'Switches off debug mode.'));
    }

    
/**
     * Gets the Kernel associated with this Console.
     *
     * @return KernelInterface A KernelInterface instance
     */
    
public function getKernel()
    {
        return 
$this->kernel;
    }

    
/**
     * Runs the current application.
     *
     * @param InputInterface  $input  An Input instance
     * @param OutputInterface $output An Output instance
     *
     * @return int 0 if everything went fine, or an error code
     */
    
public function doRun(InputInterface $inputOutputInterface $output)
    {
        
$this->kernel->boot();

        if (!
$this->commandsRegistered) {
            
$this->registerCommands();

            
$this->commandsRegistered true;
        }

        
$container $this->kernel->getContainer();

        foreach (
$this->all() as $command) {
            if (
$command instanceof ContainerAwareInterface) {
                
$command->setContainer($container);
            }
        }

        
$this->setDispatcher($container->get('event_dispatcher'));

        if (
true === $input->hasParameterOption(array('--shell''-s'))) {
            
$shell = new Shell($this);
            
$shell->setProcessIsolation($input->hasParameterOption(array('--process-isolation')));
            
$shell->run();

            return 
0;
        }

        return 
parent::doRun($input$output);
    }

    protected function 
registerCommands()
    {
        
$container $this->kernel->getContainer();

        foreach (
$this->kernel->getBundles() as $bundle) {
            if (
$bundle instanceof Bundle) {
                
$bundle->registerCommands($this);
            }
        }

        if (
$container->hasParameter('console.command.ids')) {
            foreach (
$container->getParameter('console.command.ids') as $id) {
                
$this->add($container->get($id));
            }
        }
    }
}
Онлайн: 0
Реклама