_allowModifications = (boolean) $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); } public function get($name, $default = null) { $result = $default; if (array_key_exists($name, $this->_data)) { $result = $this->_data[$name]; } return $result; } public function __get($name) { return $this->get($name); } public function __set($name, $value) { if ($this->_allowModifications) { if (is_array($value)) { $this->_data[$name] = new self($value, true); } else { $this->_data[$name] = $value; } $this->_count = count($this->_data); } else { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Zend_Config is read only'); } } public function __clone() { $array = array(); foreach ($this->_data as $key => $value) { if ($value instanceof Zend_Config) { $array[$key] = clone $value; } else { $array[$key] = $value; } } $this->_data = $array; } public function toArray() { $array = array(); $data = $this->_data; foreach ($data as $key => $value) { if ($value instanceof Zend_Config) { $array[$key] = $value->toArray(); } else { $array[$key] = $value; } } return $array; } public function __isset($name) { return isset($this->_data[$name]); } public function __unset($name) { if ($this->_allowModifications) { unset($this->_data[$name]); $this->_count = count($this->_data); $this->_skipNextIteration = true; } else { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Zend_Config is read only'); } } public function count() { return $this->_count; } public function current() { $this->_skipNextIteration = false; return current($this->_data); } public function key() { return key($this->_data); } public function next() { if ($this->_skipNextIteration) { $this->_skipNextIteration = false; return; } next($this->_data); $this->_index++; } public function rewind() { $this->_skipNextIteration = false; reset($this->_data); $this->_index = 0; } public function valid() { return $this->_index < $this->_count; } public function getSectionName() { if(is_array($this->_loadedSection) && count($this->_loadedSection) == 1) { $this->_loadedSection = $this->_loadedSection[0]; } return $this->_loadedSection; } public function areAllSectionsLoaded() { return $this->_loadedSection === null; } public function merge(Zend_Config $merge) { foreach($merge as $key => $item) { if(array_key_exists($key, $this->_data)) { if($item instanceof Zend_Config && $this->$key instanceof Zend_Config) { $this->$key = $this->$key->merge(new Zend_Config($item->toArray(), !$this->readOnly())); } else { $this->$key = $item; } } else { if($item instanceof Zend_Config) { $this->$key = new Zend_Config($item->toArray(), !$this->readOnly()); } else { $this->$key = $item; } } } return $this; } public function setReadOnly() { $this->_allowModifications = false; foreach ($this->_data as $key => $value) { if ($value instanceof Zend_Config) { $value->setReadOnly(); } } } public function readOnly() { return !$this->_allowModifications; } public function getExtends() { return $this->_extends; } public function setExtend($extendingSection, $extendedSection = null) { if ($extendedSection === null && isset($this->_extends[$extendingSection])) { unset($this->_extends[$extendingSection]); } else if ($extendedSection !== null) { $this->_extends[$extendingSection] = $extendedSection; } } protected function _assertValidExtend($extendingSection, $extendedSection) { $extendedSectionCurrent = $extendedSection; while (array_key_exists($extendedSectionCurrent, $this->_extends)) { if ($this->_extends[$extendedSectionCurrent] == $extendingSection) { require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception('Illegal circular inheritance detected'); } $extendedSectionCurrent = $this->_extends[$extendedSectionCurrent]; } $this->_extends[$extendingSection] = $extendedSection; } protected function _loadFileErrorHandler($errno, $errstr, $errfile, $errline) { if ($this->_loadFileErrorStr === null) { $this->_loadFileErrorStr = $errstr; } else { $this->_loadFileErrorStr .= (PHP_EOL . $errstr); } } protected function _arrayMergeRecursive($firstArray, $secondArray) { if (is_array($firstArray) && is_array($secondArray)) { foreach ($secondArray as $key => $value) { if (isset($firstArray[$key])) { $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value); } else { if($key === 0) { $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value)); } else { $firstArray[$key] = $value; } } } } else { $firstArray = $secondArray; } return $firstArray; } }