PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.99
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.99
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Support / Env.php

Env.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.0.99, at vendor/wpfluent/framework/src/WPFluent/Support/Env.php

108 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Framework\Support;
4
5 use RuntimeException;
6
7 class Env
8 {
9 public static function load($filePath)
10 {
11 if (!file_exists($filePath)) {
12 throw new RuntimeException(
13 "Environment file not found at: $filePath"
14 );
15 }
16
17 $lines = file(
18 $filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
19 );
20
21 foreach ($lines as $line) {
22 if (strpos(trim($line), '#') === 0) {
23 continue;
24 }
25
26 $parts = explode('=', $line, 2);
27
28 if (count($parts) < 2) {
29 continue;
30 }
31
32 $name = trim($parts[0]);
33 $value = trim($parts[1], "\"'");
34
35 switch (strtolower(trim($value))) {
36 case 'true':
37 case '(true)':
38 $value = true;
39 break;
40 case 'false':
41 case '(false)':
42 $value = false;
43 break;
44 case 'null':
45 case '(null)':
46 $value = null;
47 break;
48 case 'empty':
49 case '(empty)':
50 $value = '';
51 break;
52 }
53
54 if (!empty($name)) {
55 self::set($name, $value);
56 }
57 }
58 }
59
60 public static function get($key, $default = null)
61 {
62 return $_ENV[$key] ?? getenv($key) ?? $default;
63 }
64
65 public static function set($key, $value)
66 {
67 $_ENV[$key] = $value;
68 $_SERVER[$key] = $value;
69 putenv("$key=$value");
70 }
71
72 public static function all()
73 {
74 $envVars = [];
75
76 foreach ($_ENV as $key => $value) {
77 $envVars[$key] = $value;
78 }
79
80 foreach (getenv() as $key => $value) {
81 if (!array_key_exists($key, $envVars)) {
82 $envVars[$key] = $value;
83 }
84 }
85
86 foreach ($_SERVER as $key => $value) {
87 if (
88 strpos($key, 'HTTP_') === false &&
89 !array_key_exists($key, $envVars)
90 ) {
91 $envVars[$key] = $value;
92 }
93 }
94
95 return $envVars;
96 }
97
98 public static function dd()
99 {
100 if (function_exists('dd')) {
101 dd(static::all());
102 } else {
103 print_r(static::all());
104 die;
105 }
106 }
107 }
108