Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Config Class Reference
Inheritance diagram for Zend_Config:
Zend_Config_Ini Zend_Config_Json Zend_Config_Xml Zend_Config_Yaml

Public Member Functions

 __construct (array $array, $allowModifications=false)
 
 get ($name, $default=null)
 
 __get ($name)
 
 __set ($name, $value)
 
 __clone ()
 
 toArray ()
 
 __isset ($name)
 
 __unset ($name)
 
 count ()
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 
 getSectionName ()
 
 areAllSectionsLoaded ()
 
 merge (Zend_Config $merge)
 
 setReadOnly ()
 
 readOnly ()
 
 getExtends ()
 
 setExtend ($extendingSection, $extendedSection=null)
 
 _loadFileErrorHandler ($errno, $errstr, $errfile, $errline)
 

Protected Member Functions

 _assertValidExtend ($extendingSection, $extendedSection)
 
 _arrayMergeRecursive ($firstArray, $secondArray)
 

Protected Attributes

 $_allowModifications
 
 $_index
 
 $_count
 
 $_data
 
 $_skipNextIteration
 
 $_loadedSection
 
 $_extends = array()
 
 $_loadFileErrorStr = null
 

Detailed Description

Definition at line 29 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $array,
  $allowModifications = false 
)

Zend_Config provides a property based interface to an array. The data are read-only unless $allowModifications is set to true on construction.

Zend_Config also implements Countable and Iterator to facilitate easy access to the data.

Parameters
array$array
boolean$allowModifications
Returns
void

Definition at line 105 of file Config.php.

106  {
107  $this->_allowModifications = (boolean) $allowModifications;
108  $this->_loadedSection = null;
109  $this->_index = 0;
110  $this->_data = array();
111  foreach ($array as $key => $value) {
112  if (is_array($value)) {
113  $this->_data[$key] = new self($value, $this->_allowModifications);
114  } else {
115  $this->_data[$key] = $value;
116  }
117  }
118  $this->_count = count($this->_data);
119  }
$value
Definition: gender.phtml:16
$_allowModifications
Definition: Config.php:36

Member Function Documentation

◆ __clone()

__clone ( )

Deep clone of this instance to ensure that nested Zend_Configs are also cloned.

Returns
void

Definition at line 179 of file Config.php.

180  {
181  $array = array();
182  foreach ($this->_data as $key => $value) {
183  if ($value instanceof Zend_Config) {
184  $array[$key] = clone $value;
185  } else {
186  $array[$key] = $value;
187  }
188  }
189  $this->_data = $array;
190  }
$value
Definition: gender.phtml:16

◆ __get()

__get (   $name)

Magic function so that $obj->value will work.

Parameters
string$name
Returns
mixed

Definition at line 143 of file Config.php.

144  {
145  return $this->get($name);
146  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __isset()

__isset (   $name)

Support isset() overloading on PHP 5.1

Parameters
string$name
Returns
boolean

Definition at line 217 of file Config.php.

218  {
219  return isset($this->_data[$name]);
220  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __set()

__set (   $name,
  $value 
)

Only allow setting of a property if $allowModifications was set to true on construction. Otherwise, throw an exception.

Parameters
string$name
mixed$value
Exceptions
Zend_Config_Exception
Returns
void
See also
Zend_Config_Exception

Definition at line 157 of file Config.php.

158  {
159  if ($this->_allowModifications) {
160  if (is_array($value)) {
161  $this->_data[$name] = new self($value, true);
162  } else {
163  $this->_data[$name] = $value;
164  }
165  $this->_count = count($this->_data);
166  } else {
168  #require_once 'Zend/Config/Exception.php';
169  throw new Zend_Config_Exception('Zend_Config is read only');
170  }
171  }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __unset()

__unset (   $name)

Support unset() overloading on PHP 5.1

Parameters
string$name
Exceptions
Zend_Config_Exception
Returns
void
See also
Zend_Config_Exception

Definition at line 229 of file Config.php.

230  {
231  if ($this->_allowModifications) {
232  unset($this->_data[$name]);
233  $this->_count = count($this->_data);
234  $this->_skipNextIteration = true;
235  } else {
237  #require_once 'Zend/Config/Exception.php';
238  throw new Zend_Config_Exception('Zend_Config is read only');
239  }
240 
241  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _arrayMergeRecursive()

_arrayMergeRecursive (   $firstArray,
  $secondArray 
)
protected

Merge two arrays recursively, overwriting keys of the same name in $firstArray with the value in $secondArray.

Parameters
mixed$firstArrayFirst array
mixed$secondArraySecond array to merge into first array
Returns
array

Definition at line 464 of file Config.php.

465  {
466  if (is_array($firstArray) && is_array($secondArray)) {
467  foreach ($secondArray as $key => $value) {
468  if (isset($firstArray[$key])) {
469  $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
470  } else {
471  if($key === 0) {
472  $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value));
473  } else {
474  $firstArray[$key] = $value;
475  }
476  }
477  }
478  } else {
479  $firstArray = $secondArray;
480  }
481 
482  return $firstArray;
483  }
$value
Definition: gender.phtml:16
_arrayMergeRecursive($firstArray, $secondArray)
Definition: Config.php:464

◆ _assertValidExtend()

_assertValidExtend (   $extendingSection,
  $extendedSection 
)
protected

Throws an exception if $extendingSection may not extend $extendedSection, and tracks the section extension if it is valid.

Parameters
string$extendingSection
string$extendedSection
Exceptions
Zend_Config_Exception
Returns
void
See also
Zend_Config_Exception

Definition at line 423 of file Config.php.

424  {
425  // detect circular section inheritance
426  $extendedSectionCurrent = $extendedSection;
427  while (array_key_exists($extendedSectionCurrent, $this->_extends)) {
428  if ($this->_extends[$extendedSectionCurrent] == $extendingSection) {
430  #require_once 'Zend/Config/Exception.php';
431  throw new Zend_Config_Exception('Illegal circular inheritance detected');
432  }
433  $extendedSectionCurrent = $this->_extends[$extendedSectionCurrent];
434  }
435  // remember that this section extends another section
436  $this->_extends[$extendingSection] = $extendedSection;
437  }

◆ _loadFileErrorHandler()

_loadFileErrorHandler (   $errno,
  $errstr,
  $errfile,
  $errline 
)

Handle any errors from simplexml_load_file or parse_ini_file

Parameters
integer$errno
string$errstr
string$errfile
integer$errline

Definition at line 447 of file Config.php.

448  {
449  if ($this->_loadFileErrorStr === null) {
450  $this->_loadFileErrorStr = $errstr;
451  } else {
452  $this->_loadFileErrorStr .= (PHP_EOL . $errstr);
453  }
454  }

◆ areAllSectionsLoaded()

areAllSectionsLoaded ( )

Returns true if all sections were loaded

Returns
boolean

Definition at line 327 of file Config.php.

328  {
329  return $this->_loadedSection === null;
330  }

◆ count()

count ( )

Defined by Countable interface

Returns
int

Definition at line 248 of file Config.php.

249  {
250  return $this->_count;
251  }

◆ current()

current ( )

Defined by Iterator interface

Returns
mixed

Definition at line 258 of file Config.php.

259  {
260  $this->_skipNextIteration = false;
261  return current($this->_data);
262  }

◆ get()

get (   $name,
  $default = null 
)

Retrieve a value and return $default if there is no element set.

Parameters
string$name
mixed$default
Returns
mixed

Definition at line 128 of file Config.php.

129  {
130  $result = $default;
131  if (array_key_exists($name, $this->_data)) {
132  $result = $this->_data[$name];
133  }
134  return $result;
135  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getExtends()

getExtends ( )

Get the current extends

Returns
array

Definition at line 393 of file Config.php.

394  {
395  return $this->_extends;
396  }

◆ getSectionName()

getSectionName ( )

Returns the section name(s) loaded.

Returns
mixed

Definition at line 314 of file Config.php.

315  {
316  if(is_array($this->_loadedSection) && count($this->_loadedSection) == 1) {
317  $this->_loadedSection = $this->_loadedSection[0];
318  }
319  return $this->_loadedSection;
320  }
$_loadedSection
Definition: Config.php:74

◆ key()

key ( )

Defined by Iterator interface

Returns
mixed

Definition at line 269 of file Config.php.

270  {
271  return key($this->_data);
272  }

◆ merge()

merge ( Zend_Config  $merge)

Merge another Zend_Config with this one. The items in $merge will override the same named items in the current config.

Parameters
Zend_Config$merge
Returns
Zend_Config

Definition at line 341 of file Config.php.

342  {
343  foreach($merge as $key => $item) {
344  if(array_key_exists($key, $this->_data)) {
345  if($item instanceof Zend_Config && $this->$key instanceof Zend_Config) {
346  $this->$key = $this->$key->merge(new Zend_Config($item->toArray(), !$this->readOnly()));
347  } else {
348  $this->$key = $item;
349  }
350  } else {
351  if($item instanceof Zend_Config) {
352  $this->$key = new Zend_Config($item->toArray(), !$this->readOnly());
353  } else {
354  $this->$key = $item;
355  }
356  }
357  }
358 
359  return $this;
360  }

◆ next()

next ( )

Defined by Iterator interface

Definition at line 278 of file Config.php.

279  {
280  if ($this->_skipNextIteration) {
281  $this->_skipNextIteration = false;
282  return;
283  }
284  next($this->_data);
285  $this->_index++;
286  }

◆ readOnly()

readOnly ( )

Returns if this Zend_Config object is read only or not.

Returns
boolean

Definition at line 383 of file Config.php.

384  {
386  }
$_allowModifications
Definition: Config.php:36

◆ rewind()

rewind ( )

Defined by Iterator interface

Definition at line 292 of file Config.php.

293  {
294  $this->_skipNextIteration = false;
295  reset($this->_data);
296  $this->_index = 0;
297  }

◆ setExtend()

setExtend (   $extendingSection,
  $extendedSection = null 
)

Set an extend for Zend_Config_Writer

Parameters
string$extendingSection
string$extendedSection
Returns
void

Definition at line 405 of file Config.php.

406  {
407  if ($extendedSection === null && isset($this->_extends[$extendingSection])) {
408  unset($this->_extends[$extendingSection]);
409  } else if ($extendedSection !== null) {
410  $this->_extends[$extendingSection] = $extendedSection;
411  }
412  }

◆ setReadOnly()

setReadOnly ( )

Prevent any more modifications being made to this instance. Useful after merge() has been used to merge multiple Zend_Config objects into one object which should then not be modified again.

Definition at line 368 of file Config.php.

369  {
370  $this->_allowModifications = false;
371  foreach ($this->_data as $key => $value) {
372  if ($value instanceof Zend_Config) {
373  $value->setReadOnly();
374  }
375  }
376  }
$value
Definition: gender.phtml:16

◆ toArray()

toArray ( )

Return an associative array of the stored data.

Returns
array

Definition at line 197 of file Config.php.

198  {
199  $array = array();
201  foreach ($data as $key => $value) {
202  if ($value instanceof Zend_Config) {
203  $array[$key] = $value->toArray();
204  } else {
205  $array[$key] = $value;
206  }
207  }
208  return $array;
209  }
$value
Definition: gender.phtml:16

◆ valid()

valid ( )

Defined by Iterator interface

Returns
boolean

Definition at line 304 of file Config.php.

305  {
306  return $this->_index < $this->_count;
307  }

Field Documentation

◆ $_allowModifications

$_allowModifications
protected

Definition at line 36 of file Config.php.

◆ $_count

$_count
protected

Definition at line 50 of file Config.php.

◆ $_data

$_data
protected

Definition at line 57 of file Config.php.

◆ $_extends

$_extends = array()
protected

Definition at line 82 of file Config.php.

◆ $_index

$_index
protected

Definition at line 43 of file Config.php.

◆ $_loadedSection

$_loadedSection
protected

Definition at line 74 of file Config.php.

◆ $_loadFileErrorStr

$_loadFileErrorStr = null
protected

Definition at line 91 of file Config.php.

◆ $_skipNextIteration

$_skipNextIteration
protected

Definition at line 65 of file Config.php.


The documentation for this class was generated from the following file: