diff --git a/src/Illuminate/Foundation/EnvironmentDetector.php b/src/Illuminate/Foundation/EnvironmentDetector.php index 205f73bc1b36..2ff154c6a2eb 100644 --- a/src/Illuminate/Foundation/EnvironmentDetector.php +++ b/src/Illuminate/Foundation/EnvironmentDetector.php @@ -3,7 +3,6 @@ namespace Illuminate\Foundation; use Closure; -use Illuminate\Support\Arr; use Illuminate\Support\Str; class EnvironmentDetector @@ -48,7 +47,7 @@ protected function detectConsoleEnvironment(Closure $callback, array $args) // and if it was that automatically overrides as the environment. Otherwise, we // will check the environment as a "web" request like a typical HTTP request. if (! is_null($value = $this->getEnvironmentArgument($args))) { - return head(array_slice(explode('=', $value), 1)); + return $value; } return $this->detectWebEnvironment($callback); @@ -62,8 +61,14 @@ protected function detectConsoleEnvironment(Closure $callback, array $args) */ protected function getEnvironmentArgument(array $args) { - return Arr::first($args, function ($value) { - return Str::startsWith($value, '--env'); - }); + foreach ($args as $i => $value) { + if ($value === '--env') { + return $args[$i + 1] ?? null; + } + + if (Str::startsWith($value, '--env')) { + return head(array_slice(explode('=', $value), 1)); + } + } } } diff --git a/tests/Foundation/FoundationEnvironmentDetectorTest.php b/tests/Foundation/FoundationEnvironmentDetectorTest.php index 5678b0ed0a36..5e20de5431f6 100644 --- a/tests/Foundation/FoundationEnvironmentDetectorTest.php +++ b/tests/Foundation/FoundationEnvironmentDetectorTest.php @@ -32,4 +32,24 @@ public function testConsoleEnvironmentDetection() }, ['--env=local']); $this->assertEquals('local', $result); } + + public function testConsoleEnvironmentDetectionSeparatedWithSpace() + { + $env = new EnvironmentDetector; + + $result = $env->detect(function () { + return 'foobar'; + }, ['--env', 'local']); + $this->assertEquals('local', $result); + } + + public function testConsoleEnvironmentDetectionWithNoValue() + { + $env = new EnvironmentDetector; + + $result = $env->detect(function () { + return 'foobar'; + }, ['--env']); + $this->assertEquals('foobar', $result); + } }