Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the .env.local.php is loaded correctly #6962

Merged
merged 1 commit into from Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions manager-bundle/src/HttpKernel/ContaoKernel.php
Expand Up @@ -255,7 +255,7 @@ public static function fromRequest(string $projectDir, Request $request): HttpKe
$env = 'dev';
}

$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env;
self::loadEnv($projectDir, $env);
}

$kernel = static::create($projectDir, $env);
Expand Down Expand Up @@ -363,13 +363,11 @@ private static function create(string $projectDir, string|null $env = null): sel
private static function loadEnv(string $projectDir, string $defaultEnv = 'prod'): void
{
// Load cached env vars if the .env.local.php file exists.
// https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/4.2/config/bootstrap.php
if (\is_array($env = @include Path::join($projectDir, '.env.local.php'))) {
foreach ($env as $k => $v) {
$_ENV[$k] ??= isset($_SERVER[$k]) && !str_starts_with($k, 'HTTP_') ? $_SERVER[$k] : $v;
}
// https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/4.4/config/bootstrap.php
if (\is_array($env = @include Path::join($projectDir, '.env.local.php')) && (!isset($env['APP_ENV']) || $defaultEnv === $env['APP_ENV'])) {
(new Dotenv())->populate($env);
} elseif (file_exists($filePath = Path::join($projectDir, '.env'))) {
(new Dotenv())->usePutenv(false)->loadEnv($filePath, 'APP_ENV', $defaultEnv);
(new Dotenv())->loadEnv($filePath, 'APP_ENV', $defaultEnv);
}

$_SERVER += $_ENV;
Expand Down