1 | <?php |
||
2 | |||
3 | namespace AlibabaCloud\Client\Config; |
||
4 | |||
5 | use Exception; |
||
6 | use clagiordano\weblibs\configmanager\ConfigManager; |
||
7 | |||
8 | /** |
||
9 | * Class Config |
||
10 | * |
||
11 | * @package AlibabaCloud\Client\Config |
||
12 | */ |
||
13 | class Config |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var ConfigManager|null |
||
18 | */ |
||
19 | private static $configManager; |
||
20 | |||
21 | /** |
||
22 | * @param string $configPath |
||
23 | * |
||
24 | * @param string|null $defaultValue |
||
25 | * |
||
26 | * @return mixed |
||
27 | */ |
||
28 | 55 | public static function get($configPath, $defaultValue = null) |
|
29 | { |
||
30 | 55 | return self::getConfigManager() |
|
31 | 55 | ->getValue( |
|
32 | 55 | \strtolower($configPath), |
|
33 | $defaultValue |
||
34 | 55 | ); |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * @return ConfigManager |
||
39 | */ |
||
40 | 56 | private static function getConfigManager() |
|
41 | { |
||
42 | 56 | if (!self::$configManager instanceof ConfigManager) { |
|
43 | 2 | self::$configManager = new ConfigManager(__DIR__ . DIRECTORY_SEPARATOR . 'Data.php'); |
|
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||
44 | 2 | } |
|
45 | |||
46 | 56 | return self::$configManager; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $configPath |
||
51 | * @param mixed $newValue |
||
52 | * |
||
53 | * @return ConfigManager |
||
54 | * @throws Exception |
||
55 | */ |
||
56 | 1 | public static function set($configPath, $newValue) |
|
57 | { |
||
58 | 1 | self::getConfigManager()->setValue(\strtolower($configPath), $newValue); |
|
59 | |||
60 | 1 | return self::getConfigManager()->saveConfigFile(); |
|
61 | } |
||
62 | } |
||
63 |