[Nostromo] Refactor config load

This commit is contained in:
Andrés Montañez
2017-01-29 19:25:03 -03:00
parent 91da979151
commit 0bae8e2b1b
18 changed files with 24 additions and 53 deletions
+8
View File
@@ -66,4 +66,12 @@ abstract class AbstractCommand extends Command
$utils = new Utils();
return $utils->getStageName($this->runtime->getStage());
}
/**
* Requires the configuration to be loaded
*/
protected function requireConfig()
{
$this->getApplication()->configure();
}
}
@@ -41,6 +41,8 @@ class DumpCommand extends AbstractCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
$output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln('');
@@ -42,6 +42,8 @@ class EnvironmentsCommand extends AbstractCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
$output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln('');
+2
View File
@@ -58,6 +58,8 @@ class DeployCommand extends AbstractCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
$output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln('');
@@ -51,6 +51,8 @@ class ListCommand extends AbstractCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
$utils = new Utils();
$output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln('');
@@ -52,6 +52,8 @@ class RollbackCommand extends DeployCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->requireConfig();
$output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln('');
+6 -7
View File
@@ -40,9 +40,11 @@ class MageApplication extends Application
*/
public function __construct($file)
{
$this->file = $file;
parent::__construct('Magallanes', Mage::VERSION);
$this->file = $file;
$dispatcher = new EventDispatcher();
$this->setDispatcher($dispatcher);
$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
$output = $event->getOutput();
@@ -52,8 +54,8 @@ class MageApplication extends Application
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
});
$this->setDispatcher($dispatcher);
parent::__construct('Magallanes', Mage::VERSION);
$this->runtime = $this->instantiateRuntime();
$this->loadBuiltInCommands();
}
/**
@@ -85,12 +87,9 @@ class MageApplication extends Application
$logger->pushHandler(new StreamHandler($logfile));
}
$this->runtime = $this->instantiateRuntime();
$this->runtime->setConfiguration($config['magephp']);
$this->runtime->setLogger($logger);
$this->loadBuiltInCommands();
return true;
return;
}
throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $this->file));