Total Complexity | 24 |
Total Lines | 75 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
9 | class Env |
||
10 | { |
||
11 | public static function get($key, $default = null) |
||
12 | { |
||
13 | if ($key === 'HTTPS') { |
||
14 | if (isset($_SERVER['HTTPS'])) { |
||
15 | return !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; |
||
16 | } |
||
17 | |||
18 | return strpos((string)env('SCRIPT_URI'), 'https://') === 0; |
||
19 | } |
||
20 | |||
21 | if ($key === 'SCRIPT_NAME' && env('CGI_MODE') && isset($_ENV['SCRIPT_URL'])) { |
||
22 | $key = 'SCRIPT_URL'; |
||
23 | } |
||
24 | |||
25 | $value = $default; |
||
26 | if (isset($_SERVER[$key])) { |
||
27 | $value = $_SERVER[$key]; |
||
28 | } elseif (isset($_ENV[$key])) { |
||
29 | $value = $_ENV[$key]; |
||
30 | } elseif (getenv($key) !== false) { |
||
31 | $value = getenv($key); |
||
32 | } |
||
33 | |||
34 | if ($value === null) { |
||
35 | return self::returnDefault($key, $default); |
||
36 | } |
||
37 | |||
38 | switch (strtolower($value)) { |
||
39 | case 'true': |
||
40 | case '(true)': |
||
41 | return true; |
||
42 | case 'false': |
||
43 | case '(false)': |
||
44 | return false; |
||
45 | case 'empty': |
||
46 | case '(empty)': |
||
47 | return ''; |
||
48 | case 'null': |
||
49 | case '(null)': |
||
50 | return; |
||
51 | } |
||
52 | // if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) { |
||
53 | // return substr($value, 1, -1); |
||
54 | // } |
||
55 | |||
56 | return $value; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param $key |
||
61 | * @param $default |
||
62 | * |
||
63 | * @return array|bool|mixed|string|string[] |
||
64 | */ |
||
65 | protected static function returnDefault($key, $default) { |
||
84 | } |
||
85 | } |