getConstants(ReflectionClassConstant::IS_PUBLIC)); } private function __construct(private string $envVar) { } public static function __callStatic(string $name, array $arguments): self { if (! contains(self::cases(), $name)) { throw new InvalidArgumentException('Invalid env var: "' . $name . '"'); } return new self($name); } public function loadFromEnv(mixed $default = null): mixed { return env($this->envVar, $default); } public function existsInEnv(): bool { return $this->loadFromEnv() !== null; } }