summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-10-02 11:52:31 -0400
committerJon Pugh2017-10-02 11:52:31 -0400
commit16809b5b3dc55988344c867ee5a9b1a322d74f63 (patch)
tree0043a289c5c6d0edb2a9186d1c34db91dbc5d70c
parente6f86ede2eba1b80aaa278b6a8b99e6b744cb8ad (diff)
Reformat code according to Symfony2 guidelines.branch-version
-rw-r--r--src/Application.php119
-rw-r--r--src/Command.php55
-rw-r--r--src/Command/SaveCommand.php60
-rw-r--r--src/Command/ShellCommand.php7
-rw-r--r--src/Command/StatusCommand.php8
-rw-r--r--src/Console/Config.php47
6 files changed, 171 insertions, 125 deletions
diff --git a/src/Application.php b/src/Application.php
index 351f333..5fcc2c5 100644
--- a/src/Application.php
+++ b/src/Application.php
@@ -27,39 +27,40 @@ use Symfony\Component\Console\Application as BaseApplication;
*/
class Application extends BaseApplication
{
- /**
- * @var string
- */
- const NAME = 'Aegir Provision';
-
- /**
- * @var string
- */
- const VERSION = '4.x';
-
- /**
- * @var string
- */
- const CONSOLE_CONFIG = '.provision.yml';
-
- /**
- * @var string
- */
- const DEFAULT_TIMEZONE = 'America/New_York';
-
- public function __construct()
- {
-
- // If no timezone is set, set Default.
- if (empty(ini_get('date.timezone'))) {
- date_default_timezone_set($this::DEFAULT_TIMEZONE);
- }
- // Load Configs
- $this->config = new Config();
+ /**
+ * @var string
+ */
+ const NAME = 'Aegir Provision';
+
+ /**
+ * @var string
+ */
+ const VERSION = '4.x';
+
+ /**
+ * @var string
+ */
+ const CONSOLE_CONFIG = '.provision.yml';
+
+ /**
+ * @var string
+ */
+ const DEFAULT_TIMEZONE = 'America/New_York';
+
+ public function __construct()
+ {
+
+ // If no timezone is set, set Default.
+ if (empty(ini_get('date.timezone'))) {
+ date_default_timezone_set($this::DEFAULT_TIMEZONE);
+ }
+
+ // Load Configs
+ $this->config = new Config();
- parent::__construct($this::NAME, $this::VERSION);
- }
+ parent::__construct($this::NAME, $this::VERSION);
+ }
/**
* @var Config
@@ -88,27 +89,37 @@ class Application extends BaseApplication
$this->config = $config;
}
- /**
- * Initializes all the default commands.
- */
- protected function getDefaultCommands() {
- $commands[] = new HelpCommand();
- $commands[] = new ListCommand();
- $commands[] = new SaveCommand();
- $commands[] = new ShellCommand();
- $commands[] = new StatusCommand();
- return $commands;
- }
-
- /**
- * {@inheritdoc}
- *
- * Adds "--target" option.
- */
- protected function getDefaultInputDefinition()
- {
- $inputDefinition = parent::getDefaultInputDefinition();
- $inputDefinition->addOption(new InputOption('--target', '-t', InputOption::VALUE_NONE, 'The target context to act on.'));
- return $inputDefinition;
- }
+ /**
+ * Initializes all the default commands.
+ */
+ protected function getDefaultCommands()
+ {
+ $commands[] = new HelpCommand();
+ $commands[] = new ListCommand();
+ $commands[] = new SaveCommand();
+ $commands[] = new ShellCommand();
+ $commands[] = new StatusCommand();
+
+ return $commands;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Adds "--target" option.
+ */
+ protected function getDefaultInputDefinition()
+ {
+ $inputDefinition = parent::getDefaultInputDefinition();
+ $inputDefinition->addOption(
+ new InputOption(
+ '--target',
+ '-t',
+ InputOption::VALUE_NONE,
+ 'The target context to act on.'
+ )
+ );
+
+ return $inputDefinition;
+ }
}
diff --git a/src/Command.php b/src/Command.php
index 7a1b140..064783b 100644
--- a/src/Command.php
+++ b/src/Command.php
@@ -9,48 +9,53 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* Class Command
+ *
* @package Aegir\Provision\Command
*/
abstract class Command extends BaseCommand
{
- use CommandTrait;
+ use CommandTrait;
- /**
- * @var \Symfony\Component\Console\Input\InputInterface
- */
- protected $input;
- /**
- * @var \Symfony\Component\Console\Output\OutputInterface
- */
- protected $output;
+ /**
+ * @var \Symfony\Component\Console\Input\InputInterface
+ */
+ protected $input;
+
+ /**
+ * @var \Symfony\Component\Console\Output\OutputInterface
+ */
+ protected $output;
/**
* @var Config
*/
private $config;
- /**
- * @param InputInterface $input An InputInterface instance
- * @param OutputInterface $output An OutputInterface instance
- */
- protected function initialize(InputInterface $input, OutputInterface $output)
- {
+ /**
+ * @param InputInterface $input An InputInterface instance
+ * @param OutputInterface $output An OutputInterface instance
+ */
+ protected function initialize(
+ InputInterface $input,
+ OutputInterface $output
+ ) {
$this->input = $input;
$this->output = $output;
$this->config = $this->getApplication()->getConfig();
- }
+ }
- /**
- * Run a process.
- *
- * @param $cmd
- */
- protected function process($cmd) {
- $this->output->writeln(["Running: $cmd"]);
- shell_exec($cmd);
- }
+ /**
+ * Run a process.
+ *
+ * @param $cmd
+ */
+ protected function process($cmd)
+ {
+ $this->output->writeln(["Running: $cmd"]);
+ shell_exec($cmd);
+ }
/**
* Gets the application instance for this command.
diff --git a/src/Command/SaveCommand.php b/src/Command/SaveCommand.php
index 56f93ab..8df2203 100644
--- a/src/Command/SaveCommand.php
+++ b/src/Command/SaveCommand.php
@@ -16,33 +16,51 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class SaveCommand extends Command
{
+
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
- ->setName('save')
- ->setDescription('Save Provision Context.')
- ->setHelp('Saves a ProvisionContext object to file. Currently just passes to "drush provision-save".')
- ->setDefinition($this->getCommandDefinition())
- ;
+ ->setName('save')
+ ->setDescription('Save Provision Context.')
+ ->setHelp(
+ 'Saves a ProvisionContext object to file. Currently just passes to "drush provision-save".'
+ )
+ ->setDefinition($this->getCommandDefinition());
}
- /**
- * Generate the list of options derived from ProvisionContextType classes.
- *
- * @return \Symfony\Component\Console\Input\InputDefinition
- */
- 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.');
+ /**
+ * Generate the list of options derived from ProvisionContextType classes.
+ *
+ * @return \Symfony\Component\Console\Input\InputDefinition
+ */
+ 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.'
+ );
- // @TODO: Load up all ProvisionContextTypes and inject their options.
+ // @TODO: Load up all ProvisionContextTypes and inject their options.
- return new InputDefinition($inputDefinition);
+ return new InputDefinition($inputDefinition);
}
/**
@@ -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');
- $this->process($command);
+ $command = 'drush provision-save '.$input->getArgument('context_name');
+ $this->process($command);
}
}
diff --git a/src/Command/ShellCommand.php b/src/Command/ShellCommand.php
index 50ed4f5..a434c25 100644
--- a/src/Command/ShellCommand.php
+++ b/src/Command/ShellCommand.php
@@ -15,15 +15,16 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class ShellCommand extends Command
{
+
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
- ->setName('shell')
- ->setDescription($this->trans('commands.shell.description'))
- ->setHelp($this->trans('commands.shell.help'));
+ ->setName('shell')
+ ->setDescription($this->trans('commands.shell.description'))
+ ->setHelp($this->trans('commands.shell.help'));
}
/**
diff --git a/src/Command/StatusCommand.php b/src/Command/StatusCommand.php
index d303938..8d31aa5 100644
--- a/src/Command/StatusCommand.php
+++ b/src/Command/StatusCommand.php
@@ -17,16 +17,16 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class StatusCommand extends Command
{
+
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
- ->setName('status')
- ->setDescription('Display system status.')
- ->setHelp('Lists helpful information about your system.')
- ;
+ ->setName('status')
+ ->setDescription('Display system status.')
+ ->setHelp('Lists helpful information about your system.');
}
/**
diff --git a/src/Console/Config.php b/src/Console/Config.php
index 4af0179..9077e74 100644
--- a/src/Console/Config.php
+++ b/src/Console/Config.php
@@ -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()
+ );
}
@@ -66,18 +69,17 @@ class Config implements ConfigurationInterface
$tree_builder = new TreeBuilder();
$root_node = $tree_builder->root('aegir');
$root_node
- ->children()
- ->scalarNode('aegir_root')
- ->defaultValue('/var/aegir')
- ->end()
- ->scalarNode('script_user')
- ->defaultValue('aegir')
- ->end()
- ->scalarNode('config_path')
- ->defaultValue('/var/aegir/config')
- ->end()
- ->end();
- ;
+ ->children()
+ ->scalarNode('aegir_root')
+ ->defaultValue('/var/aegir')
+ ->end()
+ ->scalarNode('script_user')
+ ->defaultValue('aegir')
+ ->end()
+ ->scalarNode('config_path')
+ ->defaultValue('/var/aegir/config')
+ ->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;
}
@@ -119,7 +124,7 @@ class Config implements ConfigurationInterface
*
* @param string $key
* Key of the param to get.
- * @param mixed $val
+ * @param mixed $val
* Value of the param to set.
*
* @return bool
@@ -143,11 +148,11 @@ class Config implements ConfigurationInterface
/**
* Add a config param value to a config array.
*
- * @param string $key
+ * @param string $key
* Key of the group to set to.
* @param string|array $names
* Name of the new object to set.
- * @param mixed $val
+ * @param mixed $val
* Value of the new object to set.
*
* @return bool
@@ -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;
}
}