mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 08:44:11 +02:00
IcingaObject: allow to replace with plain object
This commit is contained in:
parent
f447457c40
commit
6f0c7aa2a3
@ -2738,19 +2738,26 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||
*/
|
||||
public function replaceWith(IcingaObject $object, $preserve = null)
|
||||
{
|
||||
if ($preserve === null) {
|
||||
$this->setProperties((array) $object->toPlainObject());
|
||||
} else {
|
||||
$plain = (array) $object->toPlainObject();
|
||||
foreach ($preserve as $k) {
|
||||
$v = $this->$k;
|
||||
if ($v !== null) {
|
||||
$plain[$k] = $v;
|
||||
}
|
||||
}
|
||||
return $this->replaceWithProperties($object->toPlainObject(), $preserve);
|
||||
}
|
||||
|
||||
$this->setProperties($plain);
|
||||
/**
|
||||
* @param array|object $properties
|
||||
* @param array $preserve
|
||||
* @return $this
|
||||
* @throws NotFoundError
|
||||
*/
|
||||
public function replaceWithProperties($properties, $preserve = [])
|
||||
{
|
||||
$properties = (array) $properties;
|
||||
foreach ($preserve as $k) {
|
||||
$v = $this->get($k);
|
||||
if ($v !== null) {
|
||||
$properties[$k] = $v;
|
||||
}
|
||||
}
|
||||
$this->setProperties($properties);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user