| Total Complexity | 7 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | final class Env |
||
| 11 | { |
||
| 12 | private static ?array $values = null; |
||
| 13 | |||
| 14 | private const FILE_NAME = '.env.php'; |
||
| 15 | |||
| 16 | public static function get(string $name, string $default = null): ?string |
||
| 17 | { |
||
| 18 | self::ensureValuesLoaded(); |
||
| 19 | |||
| 20 | return isset(self::$values[$name]) ? (string)self::$values[$name] : getenv($default) ?? $default; |
||
| 21 | } |
||
| 22 | |||
| 23 | public static function getBoolean(string $name, bool $default = false): bool |
||
| 24 | { |
||
| 25 | self::ensureValuesLoaded(); |
||
| 26 | |||
| 27 | return \filter_var(self::$values[$name] ?? null, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? $default; |
||
| 28 | } |
||
| 29 | |||
| 30 | public static function getInteger(string $name, int $default = 0): int |
||
| 31 | { |
||
| 32 | self::ensureValuesLoaded(); |
||
| 33 | |||
| 34 | return \filter_var(self::$values[$name] ?? null, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE) ?? $default; |
||
| 35 | } |
||
| 36 | |||
| 37 | public static function load(): void |
||
| 52 | } |
||
| 53 | |||
| 54 | private static function ensureValuesLoaded(): void |
||
| 59 | } |
||
| 60 | } |
||
| 62 |