Files
lastwar/includes/env_loader.php

33 lines
708 B
PHP
Executable File

<?php
function loadEnv(string $path): void
{
if (!file_exists($path)) {
return;
}
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) {
continue;
}
if (strpos($line, '=') !== false) {
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
$value = trim($value);
if (!array_key_exists($key, $_ENV)) {
$_ENV[$key] = $value;
}
if (!getenv($key)) {
putenv("$key=$value");
}
}
}
}
loadEnv(__DIR__ . '/../.env');