1 | <?php |
||
49 | class Config extends ObjectAbstract implements ConfigInterface, WritableInterface, \ArrayAccess, ReferenceInterface, DelegatorAwareInterface |
||
50 | { |
||
51 | use ReferenceTrait, DelegatorAwareTrait, ArrayAccessTrait, WritableTrait; |
||
52 | |||
53 | /** |
||
54 | * error type |
||
55 | * |
||
56 | * @var int |
||
57 | */ |
||
58 | const ERROR_IGNORE = 0; |
||
59 | const ERROR_WARNING = 1; |
||
60 | const ERROR_EXCEPTION = 2; |
||
61 | |||
62 | /** |
||
63 | * the config loader |
||
64 | * |
||
65 | * @var ConfigLoaderInterface |
||
66 | * @access protected |
||
67 | */ |
||
68 | protected $loader; |
||
69 | |||
70 | /** |
||
71 | * the config tree |
||
72 | * |
||
73 | * @var TreeInterface |
||
74 | * @access protected |
||
75 | */ |
||
76 | protected $config; |
||
77 | |||
78 | /** |
||
79 | * cache loaded group names |
||
80 | * |
||
81 | * @var array |
||
82 | * @access protected |
||
83 | */ |
||
84 | protected $loaded = []; |
||
85 | |||
86 | /** |
||
87 | * How to dealing with error, ignore/trigger_error/exception etc. |
||
88 | * |
||
89 | * @var int |
||
90 | * @access protected |
||
91 | */ |
||
92 | protected $error_type = self::ERROR_WARNING; |
||
93 | |||
94 | /** |
||
95 | * Constructor |
||
96 | * |
||
97 | * @param ConfigLoaderInterface $loader config loader if any |
||
98 | * @param TreeInterface $configTree config tree if any |
||
99 | * @param array $configData config data for the tree |
||
100 | * @access public |
||
101 | * @api |
||
102 | */ |
||
103 | public function __construct( |
||
111 | |||
112 | /** |
||
113 | * {@inheritDoc} |
||
114 | */ |
||
115 | public function get(/*# string */ $id, $default = null) |
||
135 | |||
136 | /** |
||
137 | * {@inheritDoc} |
||
138 | */ |
||
139 | public function has(/*# string */ $id)/*# : bool */ |
||
161 | |||
162 | /** |
||
163 | * {@inheritDoc} |
||
164 | */ |
||
165 | public function set(/*# string */ $id, $value) |
||
182 | |||
183 | /** |
||
184 | * Set error type |
||
185 | * |
||
186 | * @param int $type |
||
187 | * @return $this |
||
188 | * @access public |
||
189 | * @api |
||
190 | */ |
||
191 | public function setErrorType(/*# int */ $type) |
||
196 | |||
197 | /** |
||
198 | * Load config |
||
199 | * |
||
200 | * @param string $id |
||
201 | * @return $this |
||
202 | * @throws LogicException if current $error_type is to throw exception |
||
203 | * @access protected |
||
204 | */ |
||
205 | protected function loadConfig(/*# string */ $id) |
||
221 | |||
222 | /** |
||
223 | * Load one group config, force loading all groups if $group == '' |
||
224 | * |
||
225 | * @param string $group |
||
226 | * @return $this |
||
227 | * @throws \Exception group loading issues |
||
228 | * @access protected |
||
229 | */ |
||
230 | protected function loadByGroup(/*# string */ $group) |
||
246 | |||
247 | /** |
||
248 | * Load super globals |
||
249 | * |
||
250 | * @param string $group |
||
251 | * @return $this |
||
252 | * @throws LogicException if global unknown |
||
253 | * @access protected |
||
254 | */ |
||
255 | protected function loadGlobal(/*# string */ $group) |
||
269 | |||
270 | /** |
||
271 | * Get group name |
||
272 | * |
||
273 | * @param string $id |
||
274 | * @return string |
||
275 | * @access protected |
||
276 | */ |
||
277 | protected function getGroupName(/*# string */ $id)/*# : string */ |
||
282 | |||
283 | /** |
||
284 | * Override 'referenceLookup()' in ReferenceTrait. |
||
285 | * |
||
286 | * Delegator support goes here |
||
287 | * |
||
288 | * {@inheritDoc} |
||
289 | */ |
||
290 | protected function referenceLookup(/*# string */ $name) |
||
304 | |||
305 | /** |
||
306 | * throw exception if current $error_type is to throw exception |
||
307 | * |
||
308 | * {@inheritDoc} |
||
309 | */ |
||
310 | protected function resolveUnknown(/*# string */ $name) |
||
320 | |||
321 | /** |
||
322 | * {@inheritDoc} |
||
323 | */ |
||
324 | protected function getReference(/*# string */ $name) |
||
328 | |||
329 | /** |
||
330 | * Dealing errors |
||
331 | * |
||
332 | * @param string $message |
||
333 | * @param int $code |
||
334 | * @return $this |
||
335 | * @throws LogicException if current $error_type is to throw exception |
||
336 | * @access protected |
||
337 | */ |
||
338 | protected function throwError(/*# string */ $message, /*# int */ $code) |
||
351 | } |
||
352 |