Last active
August 29, 2015 14:12
-
-
Save mickaelandrieu/23f808a3dcbb4e20eb6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// from https://gist.github.com/thunderer/4837269 | |
// to be located in app/ folder of your Symfony application | |
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; | |
use Symfony\Component\HttpKernel\KernelInterface; | |
use Symfony\Component\HttpKernel\Kernel; | |
use Symfony\Component\HttpKernel\Bundle\Bundle; | |
use Symfony\Bundle\FrameworkBundle\Console\Shell; | |
class Application extends BaseApplication | |
{ | |
private $kernel; | |
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', null, InputOption::VALUE_NONE, 'Launch commands from shell as a separate processes.')); | |
$this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment())); | |
$this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')); | |
$this->getDefinition()->addOption(new InputOption('--scope', null, InputOption::VALUE_REQUIRED, 'Command registering scope.')); | |
} | |
public function getKernel() | |
{ | |
return $this->kernel; | |
} | |
public function doRun(InputInterface $input, OutputInterface $output) | |
{ | |
$this->registerCommands($input->getParameterOption('--scope', 'project')); | |
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($scope) | |
{ | |
$this->kernel->boot(); | |
if('none' === $scope) | |
{ | |
return; | |
} | |
foreach($this->kernel->getBundles() as $bundle) | |
{ | |
if('project' === $scope && false === strpos($bundle->getPath(), dirname(__DIR__).'/src/')) | |
{ | |
continue; | |
} | |
if($bundle instanceof Bundle) | |
{ | |
$bundle->registerCommands($this); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
// if you don't want to setup permissions the proper way, just uncomment the following PHP line | |
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information | |
//umask(0000); | |
set_time_limit(0); | |
require_once __DIR__.'/bootstrap.php.cache'; | |
require_once __DIR__.'/AppKernel.php'; | |
// require your own Console Application class | |
require_once __DIR__.'/Application.php'; | |
use Symfony\Component\Console\Input\ArgvInput; | |
use Symfony\Component\Debug\Debug; | |
$input = new ArgvInput(); | |
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); | |
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; | |
if ($debug) { | |
Debug::enable(); | |
} | |
$kernel = new AppKernel($env, $debug); | |
$application = new Application($kernel); | |
$application->run($input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment