Created
January 7, 2022 18:22
-
-
Save wijourdil/914af507cf6f0c453b2ddf5b45b33808 to your computer and use it in GitHub Desktop.
Handle multiple `.env.*` files for Lumen (written for Lumen 8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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