Zend_Config::__construct PHP Метод

__construct() публичный Метод

Zend_Config also implements Countable and Iterator to facilitate easy access to the data.
public __construct ( array $array, boolean $allowModifications = false ) : void
$array array
$allowModifications boolean
Результат void
    public function __construct(array $array, $allowModifications = false)
    {
        $this->_allowModifications = (bool) $allowModifications;
        $this->_loadedSection = null;
        $this->_index = 0;
        $this->_data = array();
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $this->_data[$key] = new self($value, $this->_allowModifications);
            } else {
                $this->_data[$key] = $value;
            }
        }
        $this->_count = count($this->_data);
    }

Usage Example

Пример #1
0
 /**
  * Loads the section $section from the config file $filename for
  * access facilitated by nested object properties.
  *
  * Sections are defined in the XML as children of the root element.
  *
  * In order to extend another section, a section defines the "extends"
  * attribute having a value of the section name from which the extending
  * section inherits values.
  *
  * Note that the keys in $section will override any keys of the same
  * name in the sections that have been included via "extends".
  *
  * @param  string  $filename
  * @param  mixed   $section
  * @param  boolean $allowModifications
  * @throws Zend_Config_Exception
  * @return void
  */
 public function __construct($filename, $section = null, $allowModifications = false)
 {
     if (empty($filename)) {
         throw new Zend_Config_Exception('Filename is not set');
     }
     $config = simplexml_load_file($filename);
     if (null === $section) {
         $dataArray = array();
         foreach ($config as $sectionName => $sectionData) {
             $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
         }
         parent::__construct($dataArray, $allowModifications);
     } elseif (is_array($section)) {
         $dataArray = array();
         foreach ($section as $sectionName) {
             if (!isset($config->{$sectionName})) {
                 throw new Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$filename}");
             }
             $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
         }
         parent::__construct($dataArray, $allowModifications);
     } else {
         if (!isset($config->{$section})) {
             throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$filename}");
         }
         $dataArray = $this->_processExtends($config, $section);
         if (!is_array($dataArray)) {
             // section in the XML file contains just one top level string
             $dataArray = array($section => $dataArray);
         }
         parent::__construct($dataArray, $allowModifications);
     }
     $this->_loadedSection = $section;
 }
All Usage Examples Of Zend_Config::__construct