1 | <?php |
||
39 | class Config extends ObjectAbstract implements ConfigInterface, ReferenceInterface, DelegatorAwareInterface |
||
40 | { |
||
41 | use ReferenceTrait, DelegatorAwareTrait; |
||
42 | |||
43 | /** |
||
44 | * error type |
||
45 | * |
||
46 | * @var int |
||
47 | */ |
||
48 | const ERROR_IGNORE = 0; |
||
49 | const ERROR_WARNING = 1; |
||
50 | const ERROR_EXCEPTION = 2; |
||
51 | |||
52 | /** |
||
53 | * the config loader |
||
54 | * |
||
55 | * @var ConfigLoaderInterface |
||
56 | * @access protected |
||
57 | */ |
||
58 | protected $loader; |
||
59 | |||
60 | /** |
||
61 | * the config tree |
||
62 | * |
||
63 | * @var TreeInterface |
||
64 | * @access protected |
||
65 | */ |
||
66 | protected $config; |
||
67 | |||
68 | /** |
||
69 | * cache loaded group names |
||
70 | * |
||
71 | * @var array |
||
72 | * @access protected |
||
73 | */ |
||
74 | protected $loaded = []; |
||
75 | |||
76 | /** |
||
77 | * How to dealing with error, ignore/trigger_error/exception etc. |
||
78 | * |
||
79 | * @var int |
||
80 | * @access protected |
||
81 | */ |
||
82 | protected $error_type; |
||
83 | |||
84 | /** |
||
85 | * Constructor |
||
86 | * |
||
87 | * @param ConfigLoaderInterface $loader |
||
88 | * @param TreeInterface $configTree |
||
89 | * @param int $errorType |
||
90 | * @access public |
||
91 | * @api |
||
92 | */ |
||
93 | public function __construct( |
||
109 | |||
110 | /** |
||
111 | * {@inheritDoc} |
||
112 | */ |
||
113 | public function get(/*# string */ $key, $default = null) |
||
133 | |||
134 | /** |
||
135 | * {@inheritDoc} |
||
136 | */ |
||
137 | public function has(/*# string */ $key)/*# : bool */ |
||
159 | |||
160 | /** |
||
161 | * Set configuration |
||
162 | * |
||
163 | * @param string $key configuration key |
||
164 | * @param mixed values |
||
165 | * @return $this |
||
166 | * @throws LogicException if error type is to throw exception |
||
167 | * @access public |
||
168 | * @api |
||
169 | */ |
||
170 | public function set(/*# string */ $key, $value) |
||
183 | |||
184 | /** |
||
185 | * Load config |
||
186 | * |
||
187 | * @param string $key |
||
188 | * @return $this |
||
189 | * @throws LogicException if current $error_type is to throw exception |
||
190 | * @access protected |
||
191 | */ |
||
192 | protected function loadConfig(/*# string */ $key) |
||
208 | |||
209 | /** |
||
210 | * Load one group config, force loading all groups if $group == '' |
||
211 | * |
||
212 | * @param string $group |
||
213 | * @return $this |
||
214 | * @throws \Exception group loading issues |
||
215 | * @access protected |
||
216 | */ |
||
217 | protected function loadByGroup(/*# string */ $group) |
||
233 | |||
234 | /** |
||
235 | * Load super globals |
||
236 | * |
||
237 | * @param string $group |
||
238 | * @return $this |
||
239 | * @throws LogicException if global unknown |
||
240 | * @access protected |
||
241 | */ |
||
242 | protected function loadGlobal(/*# string */ $group) |
||
256 | |||
257 | /** |
||
258 | * Get group name |
||
259 | * |
||
260 | * @param string $key |
||
261 | * @return string |
||
262 | * @access protected |
||
263 | */ |
||
264 | protected function getGroupName(/*# string */ $key)/*# : string */ |
||
269 | |||
270 | /** |
||
271 | * throw exception if current $error_type is to throw exception |
||
272 | * |
||
273 | * {@inheritDoc} |
||
274 | */ |
||
275 | protected function resolveUnknown(/*# string */ $name) |
||
285 | |||
286 | /** |
||
287 | * {@inheritDoc} |
||
288 | */ |
||
289 | protected function getReference(/*# string */ $name) |
||
293 | |||
294 | /** |
||
295 | * Dealing errors |
||
296 | * |
||
297 | * @param string $message |
||
298 | * @param int $code |
||
299 | * @return $this |
||
300 | * @throws LogicException if current $error_type is to throw exception |
||
301 | * @access protected |
||
302 | */ |
||
303 | protected function setError(/*# string */ $message, /*# int */ $code) |
||
316 | } |
||
317 |