Skip to content

Instantly share code, notes, and snippets.

@wijourdil
Created January 7, 2022 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wijourdil/914af507cf6f0c453b2ddf5b45b33808 to your computer and use it in GitHub Desktop.
Save wijourdil/914af507cf6f0c453b2ddf5b45b33808 to your computer and use it in GitHub Desktop.
Handle multiple `.env.*` files for Lumen (written for Lumen 8)
<?php
require_once __DIR__ . '/../vendor/autoload.php';
// COPY-PASTE THE FOLLOWING PART INTO YOUR bootstrap/app.php FILE
/*
|--------------------------------------------------------------------------
| Load Custom .env.* files
|--------------------------------------------------------------------------
|
| It is possible to define a custom .env file for each environment.
| For example, create a `.env.testing` file to define constants for
| phpunit locally.
|
*/
$currentEnv = env('APP_ENV');
if ($currentEnv === null && php_sapi_name() === 'cli') {
$input = new \Symfony\Component\Console\Input\ArgvInput();
$envParameterOption = $input->getParameterOption('--env');
if ($envParameterOption !== false) {
$currentEnv = $envParameterOption;
}
}
$envFile = null;
if (file_exists(__DIR__ . "/../.env." . $currentEnv)) {
dump("JE prends .env." . $currentEnv);
$envFile = ".env." . $currentEnv;
}
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__),
$envFile
))->bootstrap();
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment