Load site settings from dotenv and store OAuth credentials

This commit is contained in:
2026-11-23 16:53:29 +08:00
parent 1bb0554608
commit 01ede89dcd
27 changed files with 730 additions and 76 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\Config;
use Dotenv\Dotenv;
final class Environment
{
private static ?array $values = null;
public static function load(): void
{
if (self::$values !== null) {
return;
}
$file = Dotenv::createArrayBacked(dirname(__DIR__, 2))->safeLoad();
self::$values = getenv() + $file;
}
public static function get(string $name): string|false
{
self::load();
return self::$values[$name] ?? false;
}
public static function path(string $name, string $default): string
{
$path = self::get($name) ?: $default;
return str_starts_with($path, '/') ? $path : dirname(__DIR__, 2) . '/' . $path;
}
}