Zend_Config::merge PHP Метод

merge() публичный Метод

Merge another Zend_Config with this one. The items in $merge will override the same named items in the current config.
public merge ( Zend_Config $merge ) : Zend_Config
$merge Zend_Config
Результат Zend_Config
    public function merge(Zend_Config $merge)
    {
        foreach ($merge as $key => $item) {
            if (array_key_exists($key, $this->_data)) {
                if ($item instanceof Zend_Config && $this->{$key} instanceof Zend_Config) {
                    $this->{$key} = $this->{$key}->merge(new Zend_Config($item->toArray(), !$this->readOnly()));
                } else {
                    $this->{$key} = $item;
                }
            } else {
                if ($item instanceof Zend_Config) {
                    $this->{$key} = new Zend_Config($item->toArray(), !$this->readOnly());
                } else {
                    $this->{$key} = $item;
                }
            }
        }
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * Инициализация конфигурации
  */
 protected function _initConfig()
 {
     $path = APPLICATION_PATH . '/../library/Zkernel/Application/configs';
     $config = new Zend_Config(array(), true);
     $it = new DirectoryIterator($path);
     foreach ($it as $file) {
         if ($file->isFile()) {
             $fullpath = $path . '/' . $file;
             switch (substr(trim(strtolower($fullpath)), -3)) {
                 case 'ini':
                     $cfg = new Zend_Config_Ini($fullpath, $this->getEnvironment());
                     break;
                 case 'xml':
                     $cfg = new Zend_Config_Xml($fullpath, $this->getEnvironment());
                     break;
                 default:
                     throw new Zend_Config_Exception('Invalid format for config file');
                     break;
             }
             $config->merge($cfg);
         }
     }
     $config->merge(new Zend_Config($this->getOptions()));
     $this->setOptions($config->toArray());
 }
All Usage Examples Of Zend_Config::merge