mirror of
https://github.com/symfony/recipes.git
synced 2026-09-12 15:46:37 +03:00
Always load vars defined in .env files, providing .env.local.php for prod
This commit is contained in:
@@ -4,18 +4,18 @@ use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
|
||||
if (!array_key_exists('APP_ENV', $_SERVER)) {
|
||||
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] ?? null;
|
||||
}
|
||||
|
||||
if ('prod' !== $_SERVER['APP_ENV']) {
|
||||
if (!class_exists(Dotenv::class)) {
|
||||
throw new RuntimeException('The "APP_ENV" environment variable is not set to "prod". Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
|
||||
}
|
||||
|
||||
// Load cached env vars if the .env.local.php file exists
|
||||
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
|
||||
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
|
||||
$_SERVER += $env;
|
||||
$_ENV += $env;
|
||||
} elseif (!class_exists(Dotenv::class)) {
|
||||
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
|
||||
} else {
|
||||
$path = dirname(__DIR__).'/.env';
|
||||
$dotenv = new Dotenv();
|
||||
|
||||
// load all the .env files
|
||||
if (method_exists($dotenv, 'loadEnv')) {
|
||||
$dotenv->loadEnv($path);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user