From 4f7db2ec83fd10088fc65375ad97f9b39ce86f56 Mon Sep 17 00:00:00 2001 From: Niek Rabelink Date: Fri, 11 Sep 2026 15:06:27 +0200 Subject: [PATCH] feat(config): enhance .env loading to check both config/.env and root .env --- config/config.php | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/config/config.php b/config/config.php index 509c12c..78e441d 100644 --- a/config/config.php +++ b/config/config.php @@ -25,27 +25,30 @@ if (!headers_sent()) { } @ini_set('expose_php', 'off'); -// 1. Optionele .env inlezing uit de hoofdmap (uitsluitend .env, GEEN .env.example fallback) +// 1. .env inlezing (controleert zowel config/.env als hoofdmap .env) $envVars = []; -$envFile = __DIR__ . '/../.env'; -if (file_exists($envFile)) { - $lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - if ($lines !== false) { - foreach ($lines as $line) { - $line = trim($line); - if ($line === '' || str_starts_with($line, '#') || str_starts_with($line, '//')) { - continue; - } - if (strpos($line, '=') !== false) { - list($name, $value) = explode('=', $line, 2); - $name = trim($name); - $value = trim($value, " \t\n\r\0\x0B\"'"); - $envVars[$name] = $value; - $_ENV[$name] = $value; - $_SERVER[$name] = $value; - @putenv("{$name}={$value}"); +$envLocations = [__DIR__ . '/.env', __DIR__ . '/../.env']; +foreach ($envLocations as $envFile) { + if (file_exists($envFile)) { + $lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + if ($lines !== false) { + foreach ($lines as $line) { + $line = trim($line); + if ($line === '' || str_starts_with($line, '#') || str_starts_with($line, '//')) { + continue; + } + if (strpos($line, '=') !== false) { + list($name, $value) = explode('=', $line, 2); + $name = trim($name); + $value = trim($value, " \t\n\r\0\x0B\"'"); + $envVars[$name] = $value; + $_ENV[$name] = $value; + $_SERVER[$name] = $value; + @putenv("{$name}={$value}"); + } } } + break; // Eerste gevonden .env bestand is leidend } }