/**
  * Loads options from an XML file (see class description for XML format)
  * Returns either an array of options (if $ret_array is set to true) or epConfiginstance
  * @param string xml config file name 
  * @param bool return array if true 
  * @return mixed array or epConfig
  * @throws epExceptionConfig
  * @access protected
  * @static
  */
 public static function &load($cfg_file = DEF_CONFIG_FILE, $ret_array = false)
 {
     // if empty file, return either an empty array or config object
     $cfg_file = trim($cfg_file);
     if (!$cfg_file) {
         if ($ret_array) {
             return array();
         } else {
             $cfg = new epConfig();
             return $cfg;
         }
     }
     // load xml config file
     switch (epFileExtension($cfg_file)) {
         case 'xml':
             if (false === ($options = epConfig::_loadXml($cfg_file))) {
                 return false;
             }
             break;
         case 'ini':
             if (false === ($options = epConfig::_loadIni($cfg_file))) {
                 return false;
             }
             break;
         default:
             throw new epExceptionConfig('Unrecognized config file (should be either .ini or .xml)');
             return self::$false;
     }
     // return array if required
     if ($ret_array) {
         return $options;
     }
     // return epConfig
     $config = new epConfig();
     $config->merge($options);
     $config->setSource($cfg_file);
     return $config;
 }
 /**
  * Set config to the object
  * This method perfpdos array_merge (overwrite) operatoins 
  * on options and can be called multiple times
  * @param mixed array or epConfig
  * @return bool
  */
 public function setConfig($config)
 {
     $this->config->merge($config);
     return true;
 }
Exemple #3
0
 /**
  * test epConfig merge: different options 
  * same options but different values 
  */
 function testConfigMergeDiff2()
 {
     // create cfg1
     $cfg1 = new epConfig();
     $this->assertTrue($cfg1 != null);
     // create cfg2
     $cfg2 = new epConfig();
     $this->assertTrue($cfg2 != null);
     // set same options/values to cfg1 and cfg2
     for ($i = 0; $i < 10; $i++) {
         // set an option-value pair
         $option = 'option' . $i;
         $value_set = 'cfg1_value' . $i;
         // cfg1 set/get option
         $cfg1->set($option, $value_set);
         $value_get = $cfg1->get($option);
         $this->assertTrue($value_set == $value_get);
         $value_set = 'cfg2_value' . $i;
         // cfg2 set/get option
         $cfg2->set($option, $value_set);
         $value_get = $cfg2->get($option);
         $this->assertTrue($value_set == $value_get);
     }
     // merge cfg2 to cfg1
     $cfg1->merge($cfg2);
     // since options in cfg2 are the same, cfg1 should not be changed
     // set same options/values to cfg1 and cfg2
     for ($i = 0; $i < 10; $i++) {
         // values from cfg2 now have overridden cfg1's
         $option = 'option' . $i;
         $value_set = 'cfg2_value' . $i;
         $value_get = $cfg1->get($option);
         $this->assertTrue($value_set == $value_get);
     }
 }