Example #1
0
 /**
  * Load the section $section from the config file $filename into
  * an associative array.
  *
  * If any keys with $section are called "extends", then the section
  * pointed to by the "extends" is then included into the properties.
  * Note that the keys in $section will override any keys of the same
  * name in the sections that have been included via "extends".
  *
  * If any key includes a ".", then this will act as a separator to
  * create a sub-property.
  *
  * example ini file:
  *      [all]
  *      db.connection = database
  *      hostname = live
  *
  *      [staging]
  *      extends = all
  *      hostname = staging
  *
  * after calling $data = Zend_Config_Ini::load($file, 'staging'); then
  *      $data['hostname'] = staging
  *      $data['db']['connection'] = database
  *
  * @param string $filename
  * @param string $section
  * @throws Zend_Config_Exception
  * @return array
  */
 public static function load($filename, $section)
 {
     if (empty($filename)) {
         throw new Zend_Config_Exception('Filename is not set');
     }
     if (empty($section)) {
         throw new Zend_Config_Exception('Section is not set');
     }
     $iniArray = parse_ini_file($filename, true);
     if (!isset($iniArray[$section])) {
         throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$filename}");
     }
     $self = new self();
     return $self->_processExtends($iniArray, $section);
 }
Example #2
0
 /**
  * Load the section $section from the config file $filename into
  * an associative array.
  *
  * 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 string $section
  * @throws Zend_Config_Exception
  * @return array
  */
 public static function load($filename, $section)
 {
     if (empty($filename)) {
         throw new Zend_Config_Exception('Filename is not set');
     }
     if (empty($section)) {
         throw new Zend_Config_Exception('Section is not set');
     }
     $config = simplexml_load_file($filename);
     if (!isset($config->{$section})) {
         throw new Zend_Config_Exception("Section '{$section}' cannot be found in {$filename}");
     }
     $self = new self();
     return $self->_processExtends($config, $section);
 }