Skip to content

Commit

Permalink
Merge pull request #4584 from mainio/5.7.x
Browse files Browse the repository at this point in the history
[5.7] Fix installation and CONCRETE5_ENV

Former-commit-id: cfd6b5d
Former-commit-id: ebf7aa73b3c90cd8c6b7a282bf616093c145e805
  • Loading branch information
aembler committed Nov 4, 2016
2 parents f229686 + ddae1ef commit de43fba
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions web/concrete/src/Foundation/EnvironmentDetector.php
Expand Up @@ -21,14 +21,14 @@ class EnvironmentDetector {
*/
public function detect($environments, $consoleArgs = null)
{
if ($consoleArgs)
{
return $this->detectConsoleEnvironment($environments, $consoleArgs);
}
else
{
return $this->detectVariableEnvironment($environments);
if ($consoleArgs && $env = $this->detectConsoleEnvironment($environments, $consoleArgs)) {
return $env;
} elseif ($env = $this->detectClosureEnvironment($environments)) {
return $env;
} elseif ($env = $this->detectVariableEnvironment($environments)) {
return $env;
}
return $this->detectWebEnvironment($environments);
}

/**
Expand All @@ -39,14 +39,6 @@ public function detect($environments, $consoleArgs = null)
*/
protected function detectWebEnvironment($environments)
{
// If the given environment is just a Closure, we will defer the environment check
// to the Closure the developer has provided, which allows them to totally swap
// the webs environment detection logic with their own custom Closure's code.
if ($environments instanceof Closure)
{
return call_user_func($environments);
}

foreach ($environments as $environment => $hosts)
{
// To determine the current environment, we'll simply iterate through the possible
Expand Down Expand Up @@ -77,10 +69,6 @@ protected function detectConsoleEnvironment($environments, array $args)
{
return head(array_slice(explode('=', $value), 1));
}
else
{
return $this->detectVariableEnvironment($environments);
}
}

/**
Expand All @@ -93,11 +81,28 @@ protected function detectVariableEnvironment($environments)
{
if (($env = $this->getEnvironmentFromVariable()) !== false) {
return $env;
} else {
return $this->detectWebEnvironment($environments);
}
}

/**
* Set the application environment from the passed closure in case a closure
* was passed.
*
* @param mixed $environments
*
* @return string|null
*/
protected function detectClosureEnvironment($environments)
{
// If the given environment is just a Closure, we will defer the environment check
// to the Closure the developer has provided, which allows them to totally swap
// the webs environment detection logic with their own custom Closure's code.
if ($environments instanceof Closure) {
return call_user_func($environments);
}
}


/**
* Get the environment argument from the console.
*
Expand All @@ -114,7 +119,7 @@ protected function getEnvironmentArgument(array $args)

/**
* Gets the environment from the CONCRETE5_ENV environment variable.
*
*
* @return string|bool
*/
protected function getEnvironmentFromVariable()
Expand Down

0 comments on commit de43fba

Please sign in to comment.