IcingaObject: improve/reorganize resolver code

This commit is contained in:
Thomas Gelf 2015-07-31 14:52:46 +02:00
parent 40599fe824
commit c8e9369dde

View File

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