PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.2.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.2.0
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 year ago Session 1 year ago Config.php 2 years ago Db.php 2 years ago Exception.php 1 year ago LICENSE.txt 6 years ago Registry.php 2 years ago Session.php 1 year ago Version.php 2 years ago
Config.php
453 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 */
258 public function next()
259 {
260 if ($this->_skipNextIteration) {
261 $this->_skipNextIteration = \false;
262 return;
263 }
264 \next($this->_data);
265 $this->_index++;
266 }
267 /**
268 * Defined by Iterator interface
269 *
270 */
271 public function rewind()
272 {
273 $this->_skipNextIteration = \false;
274 \reset($this->_data);
275 $this->_index = 0;
276 }
277 /**
278 * Defined by Iterator interface
279 *
280 * @return boolean
281 */
282 public function valid()
283 {
284 return $this->_index < $this->_count;
285 }
286 /**
287 * Returns the section name(s) loaded.
288 *
289 * @return mixed
290 */
291 public function getSectionName()
292 {
293 if (\is_array($this->_loadedSection) && \count($this->_loadedSection) == 1) {
294 $this->_loadedSection = $this->_loadedSection[0];
295 }
296 return $this->_loadedSection;
297 }
298 /**
299 * Returns true if all sections were loaded
300 *
301 * @return boolean
302 */
303 public function areAllSectionsLoaded()
304 {
305 return $this->_loadedSection === null;
306 }
307 /**
308 * Merge another Zend_Config with this one. The items
309 * in $merge will override the same named items in
310 * the current config.
311 *
312 * @param Zend_Config $merge
313 * @return Zend_Config
314 */
315 public function merge(\Zend_Config $merge)
316 {
317 foreach ($merge as $key => $item) {
318 if (\array_key_exists($key, $this->_data)) {
319 if ($item instanceof \Zend_Config && $this->{$key} instanceof \Zend_Config) {
320 $this->{$key} = $this->{$key}->merge(new \Zend_Config($item->toArray(), !$this->readOnly()));
321 } else {
322 $this->{$key} = $item;
323 }
324 } else {
325 if ($item instanceof \Zend_Config) {
326 $this->{$key} = new \Zend_Config($item->toArray(), !$this->readOnly());
327 } else {
328 $this->{$key} = $item;
329 }
330 }
331 }
332 return $this;
333 }
334 /**
335 * Prevent any more modifications being made to this instance. Useful
336 * after merge() has been used to merge multiple Zend_Config objects
337 * into one object which should then not be modified again.
338 *
339 */
340 public function setReadOnly()
341 {
342 $this->_allowModifications = \false;
343 foreach ($this->_data as $key => $value) {
344 if ($value instanceof \Zend_Config) {
345 $value->setReadOnly();
346 }
347 }
348 }
349 /**
350 * Returns if this Zend_Config object is read only or not.
351 *
352 * @return boolean
353 */
354 public function readOnly()
355 {
356 return !$this->_allowModifications;
357 }
358 /**
359 * Get the current extends
360 *
361 * @return array
362 */
363 public function getExtends()
364 {
365 return $this->_extends;
366 }
367 /**
368 * Set an extend for Zend_Config_Writer
369 *
370 * @param string $extendingSection
371 * @param string $extendedSection
372 * @return void
373 */
374 public function setExtend($extendingSection, $extendedSection = null)
375 {
376 if ($extendedSection === null && isset($this->_extends[$extendingSection])) {
377 unset($this->_extends[$extendingSection]);
378 } else {
379 if ($extendedSection !== null) {
380 $this->_extends[$extendingSection] = $extendedSection;
381 }
382 }
383 }
384 /**
385 * Throws an exception if $extendingSection may not extend $extendedSection,
386 * and tracks the section extension if it is valid.
387 *
388 * @param string $extendingSection
389 * @param string $extendedSection
390 * @throws Zend_Config_Exception
391 * @return void
392 */
393 protected function _assertValidExtend($extendingSection, $extendedSection)
394 {
395 // detect circular section inheritance
396 $extendedSectionCurrent = $extendedSection;
397 while (\array_key_exists($extendedSectionCurrent, $this->_extends)) {
398 if ($this->_extends[$extendedSectionCurrent] == $extendingSection) {
399 /** @see Zend_Config_Exception */
400 // require_once 'Zend/Config/Exception.php';
401 throw new \Zend_Config_Exception('Illegal circular inheritance detected');
402 }
403 $extendedSectionCurrent = $this->_extends[$extendedSectionCurrent];
404 }
405 // remember that this section extends another section
406 $this->_extends[$extendingSection] = $extendedSection;
407 }
408 /**
409 * Handle any errors from simplexml_load_file or parse_ini_file
410 *
411 * @param integer $errno
412 * @param string $errstr
413 * @param string $errfile
414 * @param integer $errline
415 */
416 protected function _loadFileErrorHandler($errno, $errstr, $errfile, $errline)
417 {
418 if ($this->_loadFileErrorStr === null) {
419 $this->_loadFileErrorStr = $errstr;
420 } else {
421 $this->_loadFileErrorStr .= \PHP_EOL . $errstr;
422 }
423 }
424 /**
425 * Merge two arrays recursively, overwriting keys of the same name
426 * in $firstArray with the value in $secondArray.
427 *
428 * @param mixed $firstArray First array
429 * @param mixed $secondArray Second array to merge into first array
430 * @return array
431 */
432 protected function _arrayMergeRecursive($firstArray, $secondArray)
433 {
434 if (\is_array($firstArray) && \is_array($secondArray)) {
435 foreach ($secondArray as $key => $value) {
436 if (isset($firstArray[$key])) {
437 $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
438 } else {
439 if ($key === 0) {
440 $firstArray = array(0 => $this->_arrayMergeRecursive($firstArray, $value));
441 } else {
442 $firstArray[$key] = $value;
443 }
444 }
445 }
446 } else {
447 $firstArray = $secondArray;
448 }
449 return $firstArray;
450 }
451 }
452 }
453