20 protected static array
$data = [];
29 if (
'/' != substr(
$root, -1)) {
48 public static function load(): void
51 if (!file_exists(self::$root.
'.env')) {
55 $dotEnvContent = file_get_contents(self::$root.
'.env');
56 $entries = explode(PHP_EOL, $dotEnvContent);
57 foreach ($entries as $line) {
58 $line = preg_replace(
'/#.*$/',
'', $line);
60 preg_match(
'/^\s*(\w+)\s*=\s*(.*)\s*$/', $line, $elements);
61 if (count($elements) > 2) {
62 self::$data[$elements[1]] = trim($elements[2]);
74 public static function getEnv(
string $key): ?string
76 if (0 == count(self::$data)) {
80 return self::$data[$key] ??
null;
89 public static function setEnv(
string $key,
string $value): void
91 self::$data[$key] = $value;
static getEnv(string $key)
static setEnv(string $key, string $value)
static setRoot(string $root)