20 lines
No EOL
604 B
PHP
20 lines
No EOL
604 B
PHP
<?php
|
|
class Config {
|
|
public static function load($file = '.env') {
|
|
if (!file_exists($file)) return;
|
|
|
|
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
foreach ($lines as $line) {
|
|
// Kommentare ignorieren
|
|
if (strpos(trim($line), '#') === 0) continue;
|
|
|
|
// Key und Value trennen
|
|
list($name, $value) = explode('=', $line, 2);
|
|
$_ENV[trim($name)] = trim($value);
|
|
}
|
|
}
|
|
|
|
public static function get($key, $default = null) {
|
|
return $_ENV[$key] ?? $default;
|
|
}
|
|
} |