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) {
if (!empty($path) && file_exists($path . '/.env')) {
try {
// First try native parsing (bulletproof)
$parsed = parse_ini_file($path . '/.env', false, INI_SCANNER_RAW);
if ($parsed !== false) {
foreach ($parsed as $key => $value) {
$_ENV[$key] = trim($value);
$_SERVER[$key] = trim($value);
putenv("$key=" . trim($value));
// Manual parsing to handle comments and raw strings gracefully
$lines = file($path . '/.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$parsed = true;
foreach ($lines as $line) {
$line = trim($line);
if (empty($line) || strpos($line, '#') === 0 || strpos($line, ';') === 0) continue;
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) {
// 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) {}
}
}
}
}