35 lines
807 B
PHP
35 lines
807 B
PHP
<?php
|
|
|
|
namespace App\Core;
|
|
|
|
final class Env
|
|
{
|
|
public static function load(string $file): void
|
|
{
|
|
if (!is_file($file)) {
|
|
return;
|
|
}
|
|
|
|
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
|
|
|
|
foreach ($lines as $line) {
|
|
$trimmed = trim($line);
|
|
|
|
if ($trimmed === '' || str_starts_with($trimmed, '#')) {
|
|
continue;
|
|
}
|
|
|
|
[$name, $value] = array_pad(explode('=', $trimmed, 2), 2, '');
|
|
$name = trim($name);
|
|
$value = trim($value);
|
|
|
|
if ($value !== '' && ($value[0] === '"' || $value[0] === '\'')) {
|
|
$value = trim($value, "\"'");
|
|
}
|
|
|
|
$_ENV[$name] = $value;
|
|
$_SERVER[$name] = $value;
|
|
}
|
|
}
|
|
}
|