PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / libs / Zend / Config.php
matomo / app / libs / Zend Last commit date
Db 1 month ago Session 1 year ago Config.php 1 month ago Db.php 2 years ago Exception.php 1 year ago LICENSE.txt 6 years ago Registry.php 2 years ago Session.php 1 month ago Version.php 1 month ago
Config.php
450 lines
1 <?php
2
3 namespace {
4 /**
5 * Zend Framework
6 *
7 * LICENSE
8 *
9 * This source file is subject to the new BSD license that is bundled
10 * with this package in the file LICENSE.txt.
11 * It is also available through the world-wide-web at this URL:
12 * http://framework.zend.com/license/new-bsd
13 * If you did not receive a copy of the license and are unable to
14 * obtain it through the world-wide-web, please send an email
15 * to license@zend.com so we can send you a copy immediately.
16 *
17 * @category Zend
18 * @package Zend_Config
19 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 * @version $Id: Config.php 23775 2011-03-01 17:25:24Z ralph $
22 */
23 /**
24 * @category Zend
25 * @package Zend_Config
26 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
27 * @license http://framework.zend.com/license/new-bsd New BSD License
28 */
29 class Zend_Config implements \Countable, \Iterator
30 {
31 /**
32 * Whether in-memory modifications to configuration data are allowed
33 *
34 * @var boolean
35 */
36 protected $_allowModifications;
37 /**
38 * Iteration index
39 *
40 * @var integer
41 */
42 protected $_index;
43 /**
44 * Number of elements in configuration data
45 *
46 * @var integer
47 */
48 protected $_count;
49 /**
50 * Contains array of configuration data
51 *
52 * @var array
53 */
54 protected $_data;
55 /**
56 * Used when unsetting values during iteration to ensure we do not skip
57 * the next element
58 *
59 * @var boolean
60 */
61 protected $_skipNextIteration;
62 /**
63 * Contains which config file sections were loaded. This is null
64 * if all sections were loaded, a string name if one section is loaded
65 * and an array of string names if multiple sections were loaded.
66 *
67 * @var mixed
68 */
69 protected $_loadedSection;
70 /**
71 * This is used to track section inheritance. The keys are names of sections that
72 * extend other sections, and the values are the extended sections.
73 *
74 * @var array
75 */
76 protected $_extends = array();
77 /**
78 * Load file error string.
79 *
80 * Is null if there was no error while file loading
81 *
82 * @var string
83 */
84 protected $_loadFileErrorStr = null;
85 /**
86 * Zend_Config provides a property based interface to
87 * an array. The data are read-only unless $allowModifications
88 * is set to true on construction.
89 *
90 * Zend_Config also implements Countable and Iterator to
91 * facilitate easy access to the data.
92 *
93 * @param array $array
94 * @param boolean $allowModifications
95 * @return void
96 */
97 public function __construct(array $array, $allowModifications = \false)
98 {
99 $this->_allowModifications = (bool) $allowModifications;
100 $this->_loadedSection = null;
101 $this->_index = 0;
102 $this->_data = array();
103 foreach ($array as $key => $value) {
104 if (\is_array($value)) {
105 $this->_data[$key] = new self($value, $this->_allowModifications);
106 } else {
107 $this->_data[$key] = $value;
108 }
109 }
110 $this->_count = \count($this->_data);
111 }
112 /**
113 * Retrieve a value and return $default if there is no element set.
114 *
115 * @param string $name
116 * @param mixed $default
117 * @return mixed
118 */
119 public function get($name, $default = null)
120 {
121 $result = $default;
122 if (\array_key_exists($name, $this->_data)) {
123 $result = $this->_data[$name];
124 }
125 return $result;
126 }
127 /**
128 * Magic function so that $obj->value will work.
129 *
130 * @param string $name
131 * @return mixed
132 */
133 public function __get($name)
134 {
135 return $this->get($name);
136 }
137 /**
138 * Only allow setting of a property if $allowModifications
139 * was set to true on construction. Otherwise, throw an exception.
140 *
141 * @param string $name
142 * @param mixed $value
143 * @throws Zend_Config_Exception
144 * @return void
145 */
146 public function __set($name, $value)
147 {
148 if ($this->_allowModifications) {
149 if (\is_array($value)) {
150 $this->_data[$name] = new self($value, \true);
151 } else {
152 $this->_data[$name] = $value;
153 }
154 $this->_count = \count($this->_data);
155 } else {
156 /** @see Zend_Config_Exception */
157 // require_once 'Zend/Config/Exception.php';
158 throw new \Zend_Config_Exception('Zend_Config is read only');
159 }
160 }
161 /**
162 * Deep clone of this instance to ensure that nested Zend_Configs
163 * are also cloned.
164 *
165 * @return void
166 */
167 public function __clone()
168 {
169 $array = array();
170 foreach ($this->_data as $key => $value) {
171 if ($value instanceof \Zend_Config) {
172 $array[$key] = clone $value;
173 } else {
174 $array[$key] = $value;
175 }
176 }
177 $this->_data = $array;
178 }
179 /**
180 * Return an associative array of the stored data.
181 *
182 * @return array
183 */
184 public function toArray()
185 {
186 $array = array();
187 $data = $this->_data;
188 foreach ($data as $key => $value) {
189 if ($value instanceof \Zend_Config) {
190 $array[$key] = $value->toArray();
191 } else {
192 $array[$key] = $value;
193 }
194 }
195 return $array;
196 }
197 /**
198 * Support isset() overloading on PHP 5.1
199 *
200 * @param string $name
201 * @return boolean
202 */
203 public function __isset($name)
204 {
205 return isset($this->_data[$name]);
206 }
207 /**
208 * Support unset() overloading on PHP 5.1
209 *
210 * @param string $name
211 * @throws Zend_Config_Exception
212 * @return void
213 */
214 public function __unset($name)
215 {
216 if ($this->_allowModifications) {
217 unset($this->_data[$name]);
218 $this->_count = \count($this->_data);
219 $this->_skipNextIteration = \true;
220 } else {
221 /** @see Zend_Config_Exception */
222 // require_once 'Zend/Config/Exception.php';
223 throw new \Zend_Config_Exception('Zend_Config is read only');
224 }
225 }
226 /**
227 * Defined by Countable interface
228 *
229 * @return int
230 */
231 public function count()
232 {
233 return $this->_count;
234 }
235 /**
236 * Defined by Iterator interface
237 *
238 * @return mixed
239 */
240 public function current()
241 {
242 $this->_skipNextIteration = \false;
243 return \current($this->_data);
244 }
245 /**
246 * Defined by Iterator interface
247 *
248 * @return mixed
249 */
250 public function key()
251 {
252 return \key($this->_data);
253 }
254 /**
255 * Defined by Iterator interface
256 */
257 public function next()
258 {
259 if ($this->_skipNextIteration) {
260 $this->_skipNextIteration = \false;
261 return;
262 }
263 \next($this->_data);
264 $this->_index++;
265 }
266 /**
267 * Defined by Iterator interface
268 */
269 public function rewind()
270 {
271 $this->_skipNextIteration = \false;
272 \reset($this->_data);
273 $this->_index = 0;
274 }
275 /**
276 * Defined by Iterator interface
277 *
278 * @return boolean
279 */
280 public function valid()
281 {
282 return $this->_index < $this->_count;
283 }
284 /**
285 * Returns the section name(s) loaded.
286 *
287 * @return mixed
288 */
289 public function getSectionName()
290 {
291 if (\is_array($this->_loadedSection) && \count($this->_loadedSection) == 1) {
292 $this->_loadedSection = $this->_loadedSection[0];
293 }
294 return $this->_loadedSection;
295 }
296 /**
297 * Returns true if all sections were loaded
298 *
299 * @return boolean
300 */
301 public function areAllSectionsLoaded()
302 {
303 return $this->_loadedSection === null;
304 }
305 /**
306 * Merge another Zend_Config with this one. The items
307 * in $merge will override the same named items in
308 * the current config.
309 *
310 * @param Zend_Config $merge
311 * @return Zend_Config
312 */
313 public function merge(\Zend_Config $merge)
314 {
315 foreach ($merge as $key => $item) {
316 if (\array_key_exists($key, $this->_data)) {
317 if ($item instanceof \Zend_Config && $this->{$key} instanceof \Zend_Config) {
318 $this->{$key} = $this->{$key}->merge(new \Zend_Config($item->toArray(), !$this->readOnly()));
319 } else {
320 $this->{$key} = $item;
321 }
322 } else {
323 if ($item instanceof \Zend_Config) {
324 $this->{$key} = new \Zend_Config($item->toArray(), !$this->readOnly());
325 } else {
326 $this->{$key} = $item;
327 }
328 }
329 }
330 return $this;
331 }
332 /**
333 * Prevent any more modifications being made to this instance. Useful
334 * after merge() has been used to merge multiple Zend_Config objects
335 * into one object which should then not be modified again.
336 */
337 public function setReadOnly()
338 {
339 $this->_allowModifications = \false;
340 foreach ($this->_data as $key => $value) {
341 if ($value instanceof \Zend_Config) {
342 $value->setReadOnly();
343 }
344 }
345 }
346 /**
347 * Returns if this Zend_Config object is read only or not.
348 *
349 * @return boolean
350 */
351 public function readOnly()
352 {
353 return !$this->_allowModifications;
354 }
355 /**
356 * Get the current extends
357 *
358 * @return array
359 */
360 public function getExtends()
361 {
362 return $this->_extends;
363 }
364 /**
365 * Set an extend for Zend_Config_Writer
366 *
367 * @param string $extendingSection
368 * @param string $extendedSection
369 * @return void
370 */
371 public function setExtend($extendingSection, $extendedSection = null)
372 {
373 if ($extendedSection === null && isset($this->_extends[$extendingSection])) {
374 unset($this->_extends[$extendingSection]);
375 } else {
376 if ($extendedSection !== null) {
377 $this->_extends[$extendingSection] = $extendedSection;
378 }
379 }
380 }
381 /**
382 * Throws an exception if $extendingSection may not extend $extendedSection,
383 * and tracks the section extension if it is valid.
384 *
385 * @param string $extendingSection
386 * @param string $extendedSection
387 * @throws Zend_Config_Exception
388 * @return void
389 */
390 protected function _assertValidExtend($extendingSection, $extendedSection)
391 {
392 // detect circular section inheritance
393 $extendedSectionCurrent = $extendedSection;
394 while (\array_key_exists($extendedSectionCurrent, $this->_extends)) {
395 if ($this->_extends[$extendedSectionCurrent] == $extendingSection) {
396 /** @see Zend_Config_Exception */
397 // require_once 'Zend/Config/Exception.php';
398 throw new \Zend_Config_Exception('Illegal circular inheritance detected');
399 }
400 $extendedSectionCurrent = $this->_extends[$extendedSectionCurrent];
401 }
402 // remember that this section extends another section
403 $this->_extends[$extendingSection] = $extendedSection;
404 }
405 /**
406 * Handle any errors from simplexml_load_file or parse_ini_file
407 *
408 * @param integer $errno
409 * @param string $errstr
410 * @param string $errfile
411 * @param integer $errline
412 */
413 protected function _loadFileErrorHandler($errno, $errstr, $errfile, $errline)
414 {
415 if ($this->_loadFileErrorStr === null) {
416 $this->_loadFileErrorStr = $errstr;
417 } else {
418 $this->_loadFileErrorStr .= \PHP_EOL . $errstr;
419 }
420 }
421 /**
422 * Merge two arrays recursively, overwriting keys of the same name
423 * in $firstArray with the value in $secondArray.
424 *
425 * @param mixed $firstArray First array
426 * @param mixed $secondArray Second array to merge into first array
427 * @return array
428 */
429 protected function _arrayMergeRecursive($firstArray, $secondArray)
430 {
431 if (\is_array($firstArray) && \is_array($secondArray)) {
432 foreach ($secondArray as $key => $value) {
433 if (isset($firstArray[$key])) {
434 $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
435 } else {
436 if ($key === 0) {
437 $firstArray = array(0 => $this->_arrayMergeRecursive($firstArray, $value));
438 } else {
439 $firstArray[$key] = $value;
440 }
441 }
442 }
443 } else {
444 $firstArray = $secondArray;
445 }
446 return $firstArray;
447 }
448 }
449 }
450