1 | <?php |
||
17 | class Environment implements ConfigInterface |
||
18 | { |
||
19 | /** |
||
20 | * DELIMITER |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private const DELIMITER = '_'; |
||
25 | |||
26 | /** |
||
27 | * Store |
||
28 | * |
||
29 | * @var EnvironmentNode |
||
30 | */ |
||
31 | private $store; |
||
32 | |||
33 | /** |
||
34 | * Environment |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $environment; |
||
39 | |||
40 | /** |
||
41 | * Load config |
||
42 | * |
||
43 | * @param string $config |
||
44 | * @param string $env |
||
45 | * @return void |
||
|
|||
46 | */ |
||
47 | public function __construct(string $config = null, string $env = 'production') |
||
53 | |||
54 | |||
55 | /** |
||
56 | * Get raw format |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | public function getRaw(): array |
||
64 | |||
65 | /** |
||
66 | * Get from config |
||
67 | * |
||
68 | * @param EnvironmentNode[] $nodes |
||
69 | * @return array |
||
70 | */ |
||
71 | protected function getRawRecursive(array $nodes): array |
||
82 | |||
83 | /** |
||
84 | * Get from config |
||
85 | * |
||
86 | * @param string $name |
||
87 | * @return mixed |
||
88 | */ |
||
89 | public function __get(string $name) |
||
93 | |||
94 | |||
95 | /** |
||
96 | * Add config tree and merge it |
||
97 | * |
||
98 | * @param mixed $config |
||
99 | * @return ConfigInterface |
||
100 | */ |
||
101 | public function merge($config): ConfigInterface |
||
116 | |||
117 | |||
118 | /** |
||
119 | * Get native config format as config instance |
||
120 | * |
||
121 | * @return Config |
||
122 | */ |
||
123 | public function map($environmentVariables = null): Config |
||
137 | |||
138 | /** |
||
139 | * Filter environment variables for current environment and parse them into a tree |
||
140 | * |
||
141 | * @param array $environmentVars |
||
142 | * @return EnvironmentNode |
||
143 | */ |
||
144 | protected function parseEnvironmentVars(array $environmentVars) |
||
153 | |||
154 | /** |
||
155 | * Transform array of environment variables into a tree |
||
156 | * |
||
157 | * @param array $environmentVars |
||
158 | * @return EnvironmentNode |
||
159 | */ |
||
160 | protected function variablesToTree(array $environmentVars) |
||
180 | |||
181 | /** |
||
182 | * Get prefix for current environment |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | protected function getEnvironmentPrefix(): string |
||
190 | |||
191 | /** |
||
192 | * Remove current environment prefix from given environment variable name |
||
193 | * |
||
194 | * @param string $name |
||
195 | * @return string |
||
196 | */ |
||
197 | public function removeEnvironmentPrefix(string $name): string |
||
205 | |||
206 | /** |
||
207 | * Check if a given environment variable name begins with the current environment prefix |
||
208 | * |
||
209 | * @param string $name |
||
210 | * @return bool |
||
211 | */ |
||
212 | protected function hasEnvironmentPrefix(string $name): bool |
||
217 | |||
218 | /** |
||
219 | * Check if a given environment variable name is valid |
||
220 | * |
||
221 | * @param string $name |
||
222 | * @return bool |
||
223 | */ |
||
224 | protected function isValidEnvironmentVariable(string $name): bool |
||
230 | } |
||
231 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.