1 | <?php |
||
12 | class ConfigOverlay implements ConfigInterface |
||
13 | { |
||
14 | protected $contexts = []; |
||
15 | |||
16 | const DEFAULT_CONTEXT = 'default'; |
||
17 | const PROCESS_CONTEXT = 'process'; |
||
18 | |||
19 | public function __construct() |
||
24 | |||
25 | /** |
||
26 | * Add a named configuration object to the configuration overlay. |
||
27 | * Configuration objects added LAST have HIGHEST priority, with the |
||
28 | * exception of the fact that the process context always has the |
||
29 | * highest priority. |
||
30 | * |
||
31 | * If a context has already been added, its priority will not change. |
||
32 | */ |
||
33 | public function addContext($name, ConfigInterface $config) |
||
34 | { |
||
35 | $process = $this->contexts[self::PROCESS_CONTEXT]; |
||
36 | unset($this->contexts[self::PROCESS_CONTEXT]); |
||
37 | $this->contexts[$name] = $config; |
||
38 | $this->contexts[self::PROCESS_CONTEXT] = $process; |
||
39 | |||
40 | return $this; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Add a placeholder context that will be prioritized higher than |
||
45 | * existing contexts. This is done to ensure that contexts added |
||
46 | * later will maintain a higher priority if the placeholder context |
||
47 | * is later relaced with a different configuration set via addContext(). |
||
48 | * |
||
49 | * @param string $name |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function addPlaceholder($name) |
||
53 | { |
||
54 | return $this->addContext($name, new Config()); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Increase the priority of the named context such that it is higher |
||
59 | * in priority than any existing context except for the 'process' |
||
60 | * context. |
||
61 | * |
||
62 | * @param string $name |
||
63 | * @return $this |
||
64 | */ |
||
65 | public function increasePriority($name) |
||
66 | { |
||
67 | $config = $this->getContext($name); |
||
68 | unset($this->contexts[$name]); |
||
69 | return $this->addContext($name, $config); |
||
70 | } |
||
71 | |||
72 | public function hasContext($name) |
||
76 | |||
77 | public function getContext($name) |
||
84 | |||
85 | public function removeContext($name) |
||
86 | { |
||
87 | unset($this->contexts[$name]); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Determine if a non-default config value exists. |
||
92 | */ |
||
93 | public function findContext($key) |
||
102 | |||
103 | /** |
||
104 | * @inheritdoc |
||
105 | */ |
||
106 | public function has($key) |
||
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | public function get($key, $default = null) |
||
122 | |||
123 | /** |
||
124 | * @inheritdoc |
||
125 | */ |
||
126 | public function set($key, $value) |
||
127 | { |
||
128 | $this->contexts[self::PROCESS_CONTEXT]->set($key, $value); |
||
129 | return $this; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @inheritdoc |
||
134 | */ |
||
135 | public function import($data) |
||
139 | |||
140 | /** |
||
141 | * @inheritdoc |
||
142 | */ |
||
143 | public function export() |
||
151 | |||
152 | /** |
||
153 | * @inheritdoc |
||
154 | */ |
||
155 | public function hasDefault($key) |
||
159 | |||
160 | /** |
||
161 | * @inheritdoc |
||
162 | */ |
||
163 | public function getDefault($key, $default = null) |
||
167 | |||
168 | /** |
||
169 | * @inheritdoc |
||
170 | */ |
||
171 | public function setDefault($key, $value) |
||
172 | { |
||
176 | } |
||
177 |