diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 99eed143..89d53cf6 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -155,6 +155,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $this->getInherited('Properties'); } + public function getOriginsProperties() + { + return $this->getOrigins('Properties'); + } + public function resolveProperties() { return $this->resolve('Properties'); @@ -170,6 +175,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $this->getInherited('Fields'); } + public function getOriginsFields() + { + return $this->getOrigins('Fields'); + } + public function resolveFields() { return $this->resolve('Fields'); @@ -190,6 +200,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $this->resolve('Vars'); } + public function getOriginsVars() + { + return $this->getOrigins('Vars'); + } + public function getVars() { $vars = (object) array(); @@ -214,43 +229,52 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $res['_INHERITED_']; } + protected function getOrigins($what) + { + $func = 'resolve' . $what; + $res = $this->$func(); + return $res['_ORIGINS_']; + } + protected function resolve($what) { $vals = array(); - $vals['_MERGED_'] = (object) array(); + $vals['_MERGED_'] = (object) array(); $vals['_INHERITED_'] = (object) array(); + $vals['_ORIGINS_'] = (object) array(); $objects = $this->importedObjects(); - $objects[$this->object_name] = $this; - $get = 'get' . $what; - $getResolved = 'getResolved' . $what; - - if ($what === 'Properties') { - $blacklist = array('id', 'object_type', 'object_name'); - } else { - $blacklist = array(); - } + $get = 'get' . $what; + $getInherited = 'getInherited' . $what; + $getOrigins = 'getOrigins' . $what; foreach ($objects as $name => $object) { - $vals[$name] = (object) array(); + $origins = $object->$getOrigins(); - if ($name === $this->object_name || $this->object_name === null) { - $pvals = $object->$get(); - } else { - $pvals = $object->$getResolved(); + foreach ($object->$getInherited() as $key => $value) { + // $vals[$name]->$key = $value; + $vals['_MERGED_']->$key = $value; + $vals['_INHERITED_']->$key = $value; + $vals['_ORIGINS_']->$key = $origins->$key; } - foreach ($pvals as $key => $value) { - if (in_array($key, $blacklist)) continue; - if ($value !== null) { - $vals[$name]->$key = $value; - $vals['_MERGED_']->$key = $value; - if ($name !== $this->object_name) { - $vals['_INHERITED_']->$key = $value; - } - } + + foreach ($object->$get() as $key => $value) { + if ($value === null) continue; + $vals['_MERGED_']->$key = $value; + $vals['_INHERITED_']->$key = $value; + $vals['_ORIGINS_']->$key = $name; } } + $blacklist = array('id', 'object_type', 'object_name'); + foreach ($this->$get() as $key => $value) { + if ($value === null) continue; + if (in_array($key, $blacklist)) continue; + + // $vals[$this->object_name]->$key = $value; + $vals['_MERGED_']->$key = $value; + } + return $vals; }