Load site settings from dotenv and store OAuth credentials
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user