From 6e1d2cb19d3f99b8c46eb4017272a015a06ad5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Wed, 13 Nov 2013 18:53:41 -0200 Subject: [PATCH] Issue #28. --- Mage/Config.php | 168 ++++++++++++++++++++++++++---------------------- 1 file changed, 90 insertions(+), 78 deletions(-) diff --git a/Mage/Config.php b/Mage/Config.php index 770c03d..cf1b60c 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -64,6 +64,75 @@ class Config 'environment' => array(), ); + /** + * Parse the Command Line options + * @return boolean + */ + protected function parse($arguments) + { + foreach ($arguments as $argument) { + if (preg_match('/to:[\w]+/i', $argument)) { + $this->environment = str_replace('to:', '', $argument); + + } else if (preg_match('/--[\w]+/i', $argument)) { + $optionValue = explode('=', substr($argument, 2)); + if (count($optionValue) == 1) { + $this->parameters[$optionValue[0]] = true; + } else if (count($optionValue) == 2) { + if (strtolower($optionValue[1]) == 'true') { + $this->parameters[$optionValue[0]] = true; + } else if (strtolower($optionValue[1]) == 'false') { + $this->parameters[$optionValue[0]] = false; + } else { + $this->parameters[$optionValue[0]] = $optionValue[1]; + } + } + } else { + $this->arguments[] = $argument; + } + } + } + + /** + * Loads the General Configuration + */ + protected function loadGeneral() + { + if (file_exists('.mage/config/general.yml')) { + $this->config['general'] = spyc_load_file('.mage/config/general.yml'); + } + } + + /** + * Loads the Environment configuration + * + * @throws Exception + * @return boolean + */ + protected function loadEnvironment() + { + $environment = $this->getEnvironment(); + if (($environment != false) && file_exists('.mage/config/environment/' . $environment . '.yml')) { + $this->config['environment'] = spyc_load_file('.mage/config/environment/' . $environment . '.yml'); + + // Create temporal directory for clone + if (isset($this->config['environment']['deployment']['source']) && is_array($this->config['environment']['deployment']['source'])) { + if (trim($this->config['environment']['deployment']['source']['temporal']) == '') { + $this->config['environment']['deployment']['source']['temporal'] = '/tmp'; + } + $newTemporal = rtrim($this->config['environment']['deployment']['source']['temporal'], '/') + . '/' . md5(microtime()) . '/'; + $this->config['environment']['deployment']['source']['temporal'] = $newTemporal; + } + return true; + + } else if (($environment != '') && !file_exists('.mage/config/environment/' . $environment . '.yml')) { + throw new Exception('Environment does not exists.'); + } + + return false; + } + /** * Load the Configuration and parses the Arguments * @@ -76,6 +145,15 @@ class Config $this->loadEnvironment(); } + /** + * Reloads the configuration + */ + public function reload() + { + $this->loadGeneral(); + $this->loadEnvironment(); + } + /** * Return the invocation argument based on a position * 0 = Invoked Command Name @@ -149,15 +227,6 @@ class Config return $this->environment; } - /** - * Reloads the configuration - */ - public function reload() - { - $this->loadGeneral(); - $this->loadEnvironment(); - } - /** * Get the Tasks to execute * @@ -298,6 +367,18 @@ class Config } } + /** + * Gets Environments Full Configuration + * + * @param string $option + * @param string $default + * @return mixed + */ + public function environmentConfig($option, $default = false) + { + return $this->getEnvironmentOption($option, $default); + } + /** * Get deployment configuration * @@ -389,75 +470,6 @@ class Config return $this->releaseId; } - /** - * Parse the Command Line options - * @return boolean - */ - protected function parse($arguments) - { - foreach ($arguments as $argument) { - if (preg_match('/to:[\w]+/i', $argument)) { - $this->environment = str_replace('to:', '', $argument); - - } else if (preg_match('/--[\w]+/i', $argument)) { - $optionValue = explode('=', substr($argument, 2)); - if (count($optionValue) == 1) { - $this->parameters[$optionValue[0]] = true; - } else if (count($optionValue) == 2) { - if (strtolower($optionValue[1]) == 'true') { - $this->parameters[$optionValue[0]] = true; - } else if (strtolower($optionValue[1]) == 'false') { - $this->parameters[$optionValue[0]] = false; - } else { - $this->parameters[$optionValue[0]] = $optionValue[1]; - } - } - } else { - $this->arguments[] = $argument; - } - } - } - - /** - * Loads the General Configuration - */ - protected function loadGeneral() - { - if (file_exists('.mage/config/general.yml')) { - $this->config['general'] = spyc_load_file('.mage/config/general.yml'); - } - } - - /** - * Loads the Environment configuration - * - * @throws Exception - * @return boolean - */ - protected function loadEnvironment() - { - $environment = $this->getEnvironment(); - if (($environment != false) && file_exists('.mage/config/environment/' . $environment . '.yml')) { - $this->config['environment'] = spyc_load_file('.mage/config/environment/' . $environment . '.yml'); - - // Create temporal directory for clone - if (isset($this->config['environment']['deployment']['source']) && is_array($this->config['environment']['deployment']['source'])) { - if (trim($this->config['environment']['deployment']['source']['temporal']) == '') { - $this->config['environment']['deployment']['source']['temporal'] = '/tmp'; - } - $newTemporal = rtrim($this->config['environment']['deployment']['source']['temporal'], '/') - . '/' . md5(microtime()) . '/'; - $this->config['environment']['deployment']['source']['temporal'] = $newTemporal; - } - return true; - - } else if (($environment != '') && !file_exists('.mage/config/environment/' . $environment . '.yml')) { - throw new Exception('Environment does not exists.'); - } - - return false; - } - /** * Get Environment root option *