Total Complexity | 10 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 90% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class Params extends ConfigOutput |
||
11 | { |
||
12 | 2 | protected function calcValues(array $sources): array |
|
13 | { |
||
14 | 2 | return $this->pushEnvVars(parent::calcValues($sources)); |
|
15 | } |
||
16 | |||
17 | 2 | protected function pushEnvVars(array $data): array |
|
18 | { |
||
19 | 2 | if (empty($data)) { |
|
20 | 2 | return []; |
|
21 | } |
||
22 | |||
23 | $env = $this->builder->getConfig('envs')->getValues(); |
||
24 | |||
25 | return self::pushValues($data, $env); |
||
26 | } |
||
27 | |||
28 | 2 | public static function pushValues(array $data, array $values, string $prefix = null) |
|
29 | { |
||
30 | 2 | foreach ($data as $key => &$value) { |
|
31 | 2 | $subkey = $prefix===null ? $key : "${prefix}_$key"; |
|
32 | |||
33 | 2 | $envkey = self::getEnvKey($subkey); |
|
34 | 2 | if (isset($values[$envkey])) { |
|
35 | 2 | $value = $values[$envkey]; |
|
36 | 2 | } elseif (is_array($value)) { |
|
37 | 2 | $value = self::pushValues($value, $values, $subkey); |
|
38 | } |
||
39 | } |
||
40 | |||
41 | 2 | return $data; |
|
42 | } |
||
43 | |||
44 | 2 | private static function getEnvKey(string $key): string |
|
47 | } |
||
48 | |||
49 | 2 | protected function paramsRequired(): bool |
|
52 | } |
||
53 | } |
||
54 |