Pop\Config::merge PHP Method

merge() public method

Method to merge the values of another config object into this one
public merge ( mixed $config ) : Config
$config mixed
return Config
    public function merge($config)
    {
        $orig = $this->asArray();
        $merge = $config instanceof \Pop\Config ? $config->asArray() : $config;
        if (!is_array($merge)) {
            throw new \Exception('The config passed must be an array or an instance of Pop\\Config.');
        }
        foreach ($orig as $key => $value) {
            $merge[$key] = isset($merge[$key]) ? $merge[$key] : $value;
        }
        $this->setConfig($merge);
        $this->array = array();
        return $this;
    }

Usage Example

Example #1
0
 public function testConfigMergeException()
 {
     $this->setExpectedException('Exception');
     $cfg1 = array('db' => array('name' => 'testdb', 'host' => 'localhost', 'user' => array('username' => 'testuser', 'password' => '12test34', 'role' => 'editor')), 'nav' => array('some' => 'nav'), 'module' => 'TestModule', 'oldvalue' => 123456);
     $cfg2 = 'bad value';
     $config1 = new Config($cfg1);
     $config1->merge($cfg2);
 }
All Usage Examples Of Pop\Config::merge