1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of slick/configuration |
||
5 | * |
||
6 | * For the full copyright and license information, please view the LICENSE |
||
7 | * file that was distributed with this source code. |
||
8 | */ |
||
9 | |||
10 | namespace Slick\Configuration\Driver; |
||
11 | |||
12 | use Slick\Configuration\ConfigurationInterface; |
||
13 | |||
14 | /** |
||
15 | * Environment |
||
16 | * |
||
17 | * @package Slick\Configuration\Driver |
||
18 | */ |
||
19 | class Environment implements ConfigurationInterface |
||
20 | { |
||
21 | |||
22 | use CommonDriverMethods; |
||
23 | |||
24 | public function __construct() |
||
25 | { |
||
26 | $envVars = getenv(); |
||
27 | if (!is_array($envVars)) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
28 | return; |
||
29 | } |
||
30 | |||
31 | foreach ($envVars as $key => $value) { |
||
32 | $this->set($this->createKey($key), $value); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | private function createKey(string $envName): string |
||
37 | { |
||
38 | return trim(strtolower(str_replace('_', '.', $envName)), '.'); |
||
39 | } |
||
40 | } |
||
41 |