diff --git a/src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php b/src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php index 03914738d960..7bdedac15c19 100644 --- a/src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php +++ b/src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php @@ -4,6 +4,7 @@ use Dotenv\Dotenv; use Dotenv\Exception\InvalidPathException; +use Symfony\Component\Console\Input\ArgvInput; use Illuminate\Contracts\Foundation\Application; class DetectEnvironment @@ -35,12 +36,36 @@ public function bootstrap(Application $app) */ protected function checkForSpecificEnvironmentFile($app) { + if (php_sapi_name() == 'cli') { + $input = new ArgvInput; + + if ($input->hasParameterOption('--env')) { + $file = $app->environmentFile().'.'.$input->getParameterOption('--env'); + + $this->loadEnvironmentFile($app, $file); + } + } + if (! env('APP_ENV')) { return; } - $file = $app->environmentFile().'.'.env('APP_ENV'); + if (empty($file)) { + $file = $app->environmentFile().'.'.env('APP_ENV'); + + $this->loadEnvironmentFile($app, $file); + } + } + /** + * Load a custom environment file. + * + * @param \Illuminate\Contracts\Foundation\Application $app + * @param string $file + * @return void + */ + protected function loadEnvironmentFile($app, $file) + { if (file_exists($app->environmentPath().'/'.$file)) { $app->loadEnvironmentFrom($file); }