Beispiel #1
0
 /**
  * Loads the section $section from the config file (or string $xml 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".
  * 
  * The $options parameter may be provided as either a boolean or an array.
  * If provided as a boolean, this sets the $allowModifications option of
  * IfwPsn_Vendor_Zend_Config. If provided as an array, there are two configuration
  * directives that may be set. For example:
  *
  * $options = array(
  *     'allowModifications' => false,
  *     'skipExtends'        => false
  *      );
  *
  * @param  string        $xml     XML file or string to process
  * @param  mixed         $section Section to process
  * @param  array|boolean $options 
  * @throws IfwPsn_Vendor_Zend_Config_Exception When xml is not set or cannot be loaded
  * @throws IfwPsn_Vendor_Zend_Config_Exception When section $sectionName cannot be found in $xml
  */
 public function __construct($xml, $section = null, $options = false)
 {
     if (empty($xml)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception('Filename is not set');
     }
     $allowModifications = false;
     if (is_bool($options)) {
         $allowModifications = $options;
     } elseif (is_array($options)) {
         if (isset($options['allowModifications'])) {
             $allowModifications = (bool) $options['allowModifications'];
         }
         if (isset($options['skipExtends'])) {
             $this->_skipExtends = (bool) $options['skipExtends'];
         }
     }
     set_error_handler(array($this, '_loadFileErrorHandler'));
     // Warnings and errors are suppressed
     if (strstr($xml, '<?xml')) {
         $config = IfwPsn_Vendor_Zend_Xml_Security::scan($xml);
     } else {
         try {
             if (!($config = IfwPsn_Vendor_Zend_Xml_Security::scanFile($xml))) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Config_Exception("Error failed to load {$xml} file");
             }
         } catch (IfwPsn_Vendor_Zend_Xml_Exception $e) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
             throw new IfwPsn_Vendor_Zend_Config_Exception($e->getMessage());
         }
     }
     restore_error_handler();
     // Check if there was a error while loading file
     if ($this->_loadFileErrorStr !== null) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
         throw new IfwPsn_Vendor_Zend_Config_Exception($this->_loadFileErrorStr);
     }
     if ($section === null) {
         $dataArray = array();
         foreach ($config as $sectionName => $sectionData) {
             $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
         }
         parent::__construct($dataArray, $allowModifications);
     } else {
         if (is_array($section)) {
             $dataArray = array();
             foreach ($section as $sectionName) {
                 if (!isset($config->{$sectionName})) {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Config_Exception("Section '{$sectionName}' cannot be found in {$xml}");
                 }
                 $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
             }
             parent::__construct($dataArray, $allowModifications);
         } else {
             if (!isset($config->{$section})) {
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Config/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Config_Exception("Section '{$section}' cannot be found in {$xml}");
             }
             $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;
 }