1 | <?php |
||
17 | final class Configuration implements ConfigurationInterface |
||
18 | { |
||
19 | /** @var array<string, mixed> */ |
||
20 | private $config; |
||
21 | |||
22 | /** |
||
23 | * @param array<string, mixed> $config |
||
24 | */ |
||
25 | 3231 | public function __construct(array $config = []) |
|
26 | { |
||
27 | 3231 | $this->config = $config; |
|
28 | 3231 | } |
|
29 | |||
30 | 2937 | public function merge(array $config = []) |
|
31 | { |
||
32 | 2937 | $this->config = \array_replace_recursive($this->config, $config); |
|
33 | 2937 | } |
|
34 | |||
35 | 24 | public function replace(array $config = []) |
|
36 | { |
||
37 | 24 | $this->config = $config; |
|
38 | 24 | } |
|
39 | |||
40 | 3078 | public function get(?string $key = null, $default = null) |
|
41 | { |
||
42 | 3078 | if ($key === null) { |
|
43 | 18 | @\trigger_error('Calling Configuration::get() without a $key is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED); |
|
44 | |||
45 | 18 | return $this->config; |
|
46 | } |
||
47 | |||
48 | // accept a/b/c as ['a']['b']['c'] |
||
49 | 3078 | if (\strpos($key, '/')) { |
|
50 | 2991 | return $this->getConfigByPath($key, $default); |
|
51 | } |
||
52 | |||
53 | 3021 | if (!isset($this->config[$key])) { |
|
54 | 2952 | return $default; |
|
55 | } |
||
56 | |||
57 | 2988 | return $this->config[$key]; |
|
58 | } |
||
59 | |||
60 | 21 | public function set(string $key, $value = null) |
|
61 | { |
||
62 | 21 | if (\func_num_args() === 1) { |
|
63 | @\trigger_error('Calling Configuration::set() without a $value is deprecated in league/commonmark 1.6 and will not be allowed in 2.0', \E_USER_DEPRECATED); |
||
64 | } |
||
65 | |||
66 | // accept a/b/c as ['a']['b']['c'] |
||
67 | 21 | if (\strpos($key, '/')) { |
|
68 | 12 | $this->setByPath($key, $value); |
|
69 | } |
||
70 | |||
71 | 21 | $this->config[$key] = $value; |
|
72 | 21 | } |
|
73 | |||
74 | 3 | public function exists(string $key): bool |
|
75 | { |
||
76 | 3 | return $this->getConfigByPath($key, self::MISSING) !== self::MISSING; |
|
|
|||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param string $keyPath |
||
81 | * @param string|null $default |
||
82 | * |
||
83 | * @return mixed|null |
||
84 | */ |
||
85 | 2994 | private function getConfigByPath(string $keyPath, $default = null) |
|
99 | |||
100 | /** |
||
101 | * @param string $keyPath |
||
102 | * @param string|null $value |
||
103 | */ |
||
104 | 12 | private function setByPath(string $keyPath, $value = null): void |
|
122 | } |
||
123 |
This class constant has been deprecated.