Commit 16809b5b authored by Jon Pugh's avatar Jon Pugh

Reformat code according to Symfony2 guidelines.

parent e6f86ede
......@@ -27,6 +27,7 @@ use Symfony\Component\Console\Application as BaseApplication;
*/
class Application extends BaseApplication
{
/**
* @var string
*/
......@@ -91,12 +92,14 @@ class Application extends BaseApplication
/**
* Initializes all the default commands.
*/
protected function getDefaultCommands() {
protected function getDefaultCommands()
{
$commands[] = new HelpCommand();
$commands[] = new ListCommand();
$commands[] = new SaveCommand();
$commands[] = new ShellCommand();
$commands[] = new StatusCommand();
return $commands;
}
......@@ -108,7 +111,15 @@ class Application extends BaseApplication
protected function getDefaultInputDefinition()
{
$inputDefinition = parent::getDefaultInputDefinition();
$inputDefinition->addOption(new InputOption('--target', '-t', InputOption::VALUE_NONE, 'The target context to act on.'));
$inputDefinition->addOption(
new InputOption(
'--target',
'-t',
InputOption::VALUE_NONE,
'The target context to act on.'
)
);
return $inputDefinition;
}
}
......@@ -9,10 +9,12 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* Class Command
*
* @package Aegir\Provision\Command
*/
abstract class Command extends BaseCommand
{
use CommandTrait;
......@@ -35,8 +37,10 @@ abstract class Command extends BaseCommand
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
protected function initialize(
InputInterface $input,
OutputInterface $output
) {
$this->input = $input;
$this->output = $output;
$this->config = $this->getApplication()->getConfig();
......@@ -47,7 +51,8 @@ abstract class Command extends BaseCommand
*
* @param $cmd
*/
protected function process($cmd) {
protected function process($cmd)
{
$this->output->writeln(["Running: $cmd"]);
shell_exec($cmd);
}
......
......@@ -16,6 +16,7 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class SaveCommand extends Command
{
/**
* {@inheritdoc}
*/
......@@ -24,9 +25,10 @@ class SaveCommand extends Command
$this
->setName('save')
->setDescription('Save Provision Context.')
->setHelp('Saves a ProvisionContext object to file. Currently just passes to "drush provision-save".')
->setDefinition($this->getCommandDefinition())
;
->setHelp(
'Saves a ProvisionContext object to file. Currently just passes to "drush provision-save".'
)
->setDefinition($this->getCommandDefinition());
}
/**
......@@ -34,11 +36,27 @@ class SaveCommand extends Command
*
* @return \Symfony\Component\Console\Input\InputDefinition
*/
protected function getCommandDefinition() {
protected function getCommandDefinition()
{
$inputDefinition = [];
$inputDefinition[] = new InputArgument('context_name', InputArgument::REQUIRED, 'Context to save');
$inputDefinition[] = new InputOption('context_type', NULL, InputOption::VALUE_OPTIONAL, 'server, platform, or site; default server', 'server');
$inputDefinition[] = new InputOption('delete', NULL, InputOption::VALUE_OPTIONAL, 'Remove the alias.');
$inputDefinition[] = new InputArgument(
'context_name',
InputArgument::REQUIRED,
'Context to save'
);
$inputDefinition[] = new InputOption(
'context_type',
null,
InputOption::VALUE_OPTIONAL,
'server, platform, or site; default server',
'server'
);
$inputDefinition[] = new InputOption(
'delete',
null,
InputOption::VALUE_OPTIONAL,
'Remove the alias.'
);
// @TODO: Load up all ProvisionContextTypes and inject their options.
......@@ -50,9 +68,11 @@ class SaveCommand extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("Saving context: " . $input->getArgument('context_name'));
$output->writeln(
"Saving context: ".$input->getArgument('context_name')
);
$command = 'drush provision-save ' . $input->getArgument('context_name');
$command = 'drush provision-save '.$input->getArgument('context_name');
$this->process($command);
}
}
......@@ -15,6 +15,7 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class ShellCommand extends Command
{
/**
* {@inheritdoc}
*/
......
......@@ -17,6 +17,7 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class StatusCommand extends Command
{
/**
* {@inheritdoc}
*/
......@@ -25,8 +26,7 @@ class StatusCommand extends Command
$this
->setName('status')
->setDescription('Display system status.')
->setHelp('Lists helpful information about your system.')
;
->setHelp('Lists helpful information about your system.');
}
/**
......
......@@ -16,12 +16,13 @@ use Symfony\Component\Yaml\Yaml;
*/
class Config implements ConfigurationInterface
{
/**
* Configuration values array.
*
* @var array
*/
private $config = array();
private $config = [];
/**
* Path to config YML file.
......@@ -42,7 +43,7 @@ class Config implements ConfigurationInterface
*/
public function __construct()
{
$this->config_path = $this->getHomeDir() . '/' . $this->config_filename;
$this->config_path = $this->getHomeDir().'/'.$this->config_filename;
try {
$processor = new Processor();
......@@ -52,7 +53,9 @@ class Config implements ConfigurationInterface
}
$this->config = $processor->processConfiguration($this, $configs);
} catch (\Exception $e) {
throw new \Exception('There is an error with your configuration: '.$e->getMessage());
throw new \Exception(
'There is an error with your configuration: '.$e->getMessage()
);
}
......@@ -76,8 +79,7 @@ class Config implements ConfigurationInterface
->scalarNode('config_path')
->defaultValue('/var/aegir/config')
->end()
->end();
;
->end();;
return $tree_builder;
}
......@@ -94,7 +96,10 @@ class Config implements ConfigurationInterface
public function get($key, $name = null)
{
if ($name) {
return array_key_exists($name, $this->config[$key]) ? $this->config[$key][$name] : null;
return array_key_exists(
$name,
$this->config[$key]
) ? $this->config[$key][$name] : null;
} else {
return $this->has($key) ? $this->config[$key] : null;
}
......@@ -187,6 +192,7 @@ class Config implements ConfigurationInterface
/**
* Saves the config class to file.
*
* @return bool
*/
public function save()
......@@ -198,6 +204,7 @@ class Config implements ConfigurationInterface
try {
$fs->dumpFile($this->config_path, $dumper->dump($this->config, 10));
return true;
} catch (IOExceptionInterface $e) {
return false;
......@@ -208,6 +215,7 @@ class Config implements ConfigurationInterface
* Returns the appropriate home directory.
*
* Adapted from Terminus Package Manager by Ed Reel
*
* @author Ed Reel <@uberhacker>
* @url https://github.com/uberhacker/tpm
*
......@@ -225,6 +233,7 @@ class Config implements ConfigurationInterface
$home = getenv('HOMEPATH');
}
}
return $home;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment