This commit is contained in:
Andrés Montañez 2013-11-13 18:53:41 -02:00
parent 03b158c0a5
commit 6e1d2cb19d

View file

@ -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
*