From ddae1efefd4233697e3a41ba1b07445f68f64a1e Mon Sep 17 00:00:00 2001 From: Antti Hukkanen Date: Wed, 2 Nov 2016 18:01:21 +0200 Subject: [PATCH] Fix #4583 for 5.7 Former-commit-id: 6e0eb7e3350405a3124e2bec8f96f6812aa47ad7 Former-commit-id: 7447347a9c0e1f1c97686899a47232797e929b99 --- .../src/Foundation/EnvironmentDetector.php | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/web/concrete/src/Foundation/EnvironmentDetector.php b/web/concrete/src/Foundation/EnvironmentDetector.php index 863be5074f3..c9b28839bb0 100644 --- a/web/concrete/src/Foundation/EnvironmentDetector.php +++ b/web/concrete/src/Foundation/EnvironmentDetector.php @@ -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); } /** @@ -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 @@ -77,10 +69,6 @@ protected function detectConsoleEnvironment($environments, array $args) { return head(array_slice(explode('=', $value), 1)); } - else - { - return $this->detectVariableEnvironment($environments); - } } /** @@ -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. * @@ -114,7 +119,7 @@ protected function getEnvironmentArgument(array $args) /** * Gets the environment from the CONCRETE5_ENV environment variable. - * + * * @return string|bool */ protected function getEnvironmentFromVariable()