File size: 597 Bytes
9694b21 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?php
// /api/utils/Config.php
class Config {
private static $env = [];
public static function load(string $path) {
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;
list($name, $value) = explode('=', $line, 2);
self::$env[trim($name)] = trim($value);
}
}
public static function get(string $key, $default = null) {
return self::$env[$key] ?? getenv($key) ?: $default;
}
}
|