2015-06-29 16:11:01 +02:00
|
|
|
<?php namespace Todaymade\Daux;
|
|
|
|
|
|
|
|
use ArrayObject;
|
|
|
|
|
2015-07-17 23:38:06 +02:00
|
|
|
class Config extends ArrayObject
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Merge an array into the object
|
|
|
|
*
|
|
|
|
* @param array $newValues
|
|
|
|
* @param bool $override
|
|
|
|
*/
|
|
|
|
public function merge($newValues, $override = true)
|
|
|
|
{
|
2015-06-29 16:11:01 +02:00
|
|
|
foreach ($newValues as $key => $value) {
|
2015-07-17 23:38:06 +02:00
|
|
|
if ($override === false && array_key_exists($key, $this)) {
|
2015-06-29 16:11:01 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 23:38:06 +02:00
|
|
|
/**
|
|
|
|
* Merge an array into the object, ignore already added keys.
|
|
|
|
*
|
|
|
|
* @param $newValues
|
|
|
|
*/
|
|
|
|
public function conservativeMerge($newValues)
|
|
|
|
{
|
2015-06-29 16:11:01 +02:00
|
|
|
$this->merge($newValues, false);
|
|
|
|
}
|
|
|
|
}
|