/**
* 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;
}