_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 Zend_Config($value, $this->_allowModifications); } else { $this->_data[$key] = $value; } } $this->_count = count($this->_data); } /** * Magic function so that $obj->value will work. * * @param string $name * @return mixed */ public function __get($name) { $result = null; if (isset($this->_data[$name])) { $result = $this->_data[$name]; } return $result; } /** * Only allow setting of a property if $allowModifications * was set to true on construction. Otherwise, throw an exception. * * @param string $name * @param mixed $value * @throws Zend_Config_Exception */ public function __set($name, $value) { if ($this->_allowModifications) { if (is_array($value)) { $this->_data[$name] = new Zend_Config($value, true); } else { $this->_data[$name] = $value; } $this->_count = count($this->_data); } else { throw new Zend_Config_Exception('Zend_Config is read only'); } } /** * Return an associative array of the stored data. * * @return array */ public function asArray() { $array = array(); foreach ($this->_data as $key => $value) { if (is_object($value)) { $array[$key] = $value->asArray(); } else { $array[$key] = $value; } } return $array; } /** * Support isset() overloading on PHP 5.1 * * @param string $name * @return boolean */ protected function __isset($name) { return isset($this->_data[$name]); } /** * Defined by Countable interface * * @return int */ public function count() { return $this->_count; } /** * Defined by Iterator interface * * @return mixed */ public function current() { return current($this->_data); } /** * Defined by Iterator interface * * @return mixed */ public function key() { return key($this->_data); } /** * Defined by Iterator interface * */ public function next() { next($this->_data); $this->_index++; } /** * Defined by Iterator interface * */ public function rewind() { reset($this->_data); $this->_index = 0; } /** * Defined by Iterator interface * * @return boolean */ public function valid() { return $this->_index < $this->_count; } /** * Returns the section name(s) loaded. * * @return mixed */ public function getSectionName() { return $this->_loadedSection; } /** * Returns true if all sections were loaded * * @return boolean */ public function areAllSectionsLoaded() { return $this->_loadedSection === null; } /** * Throws an exception if $extendingSection may not extend $extendedSection, * and tracks the section extension if it is valid. * * @param string $extendingSection * @param string $extendedSection * @throws Zend_Config_Exception */ protected function _assertValidExtend($extendingSection, $extendedSection) { // detect circular section inheritance $extendedSectionCurrent = $extendedSection; while (isset($this->_extends[$extendedSectionCurrent])) { if ($this->_extends[$extendedSectionCurrent] == $extendingSection) { throw new Zend_Config_Exception('Illegal circular inheritance detected'); } $extendedSectionCurrent = $this->_extends[$extendedSectionCurrent]; } // remember that this section extends another section $this->_extends[$extendingSection] = $extendedSection; } }