Update: 2026-05-15 21:59:06

This commit is contained in:
Hamza-Ayed
2026-05-15 21:59:06 +03:00
parent b66a91038c
commit fc4206cce8

View File

@@ -23,27 +23,34 @@ $envData = [];
foreach ($searchPaths as $path) { foreach ($searchPaths as $path) {
if (!empty($path) && file_exists($path . '/.env')) { if (!empty($path) && file_exists($path . '/.env')) {
try { try {
// First try native parsing (bulletproof) // Manual parsing to handle comments and raw strings gracefully
$parsed = parse_ini_file($path . '/.env', false, INI_SCANNER_RAW); $lines = file($path . '/.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($parsed !== false) { $parsed = true;
foreach ($parsed as $key => $value) { foreach ($lines as $line) {
$_ENV[$key] = trim($value); $line = trim($line);
$_SERVER[$key] = trim($value); if (empty($line) || strpos($line, '#') === 0 || strpos($line, ';') === 0) continue;
putenv("$key=" . trim($value));
if (strpos($line, '=') !== false) {
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value, " \t\n\r\0\x0B\"'"); // remove quotes
$_ENV[$key] = $value;
$_SERVER[$key] = $value;
putenv("$key=$value");
} }
$envLoaded = true;
break;
}
// Fallback to Dotenv library
if (class_exists('Dotenv\Dotenv')) {
$dotenv = Dotenv\Dotenv::createImmutable($path);
$dotenv->load();
$envLoaded = true;
break;
} }
$envLoaded = true;
break;
} catch (Exception $e) { } catch (Exception $e) {
// Try next path // Fallback to Dotenv library if manual parsing somehow fails
if (class_exists('Dotenv\Dotenv')) {
try {
$dotenv = Dotenv\Dotenv::createImmutable($path);
$dotenv->load();
$envLoaded = true;
break;
} catch (Exception $inner) {}
}
} }
} }
} }