IcingaObject: resolving methods should be generic

This commit is contained in:
Thomas Gelf 2015-07-30 11:39:00 +02:00
parent 5b3806532f
commit 3d205724c3
1 changed files with 96 additions and 14 deletions

View File

@ -139,37 +139,119 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->importedObjects;
}
public function clearImportedObjects()
{
$this->importedObjects = null;
return $this;
}
public function getResolvedProperties()
{
$res = $this->resolveProperties();
return $res['_MERGED_'];
return $this->getResolved('Properties');
}
public function getInheritedProperties()
{
return $this->getInherited('Properties');
}
public function resolveProperties()
{
$props = array();
$props['_MERGED_'] = (object) array();
$objects = $this->importedObjects();
return $this->resolve('Properties');
}
public function getResolvedFields()
{
return $this->getResolved('Fields');
}
public function getInheritedFields()
{
return $this->getInherited('Fields');
}
public function resolveFields()
{
return $this->resolve('Fields');
}
public function getResolvedVars()
{
return $this->getResolved('Vars');
}
public function getInheritedVars()
{
return $this->getInherited('Vars');
}
public function resolveVars()
{
return $this->resolve('Vars');
}
public function getVars()
{
$vars = (object) array();
foreach ($this->vars() as $key => $var) {
$vars->$key = $var->getValue();
}
return $vars;
}
protected function getResolved($what)
{
$func = 'resolve' . $what;
$res = $this->$func();
return $res['_MERGED_'];
}
protected function getInherited($what)
{
$func = 'resolve' . $what;
$res = $this->$func();
return $res['_INHERITED_'];
}
protected function resolve($what)
{
$vals = array();
$vals['_MERGED_'] = (object) array();
$vals['_INHERITED_'] = (object) array();
$objects = $this->importedObjects();
$objects[$this->object_name] = $this;
$blacklist = array('id', 'object_type', 'object_name');
$get = 'get' . $what;
$getResolved = 'getResolved' . $what;
if ($what === 'Properties') {
$blacklist = array('id', 'object_type', 'object_name');
} else {
$blacklist = array();
}
foreach ($objects as $name => $object) {
$props[$name] = (object) array();
if ($name === $this->object_name) {
$pprops = $object->getProperties();
$vals[$name] = (object) array();
if ($name === $this->object_name || $this->object_name === null) {
$pvals = $object->$get();
} else {
$pprops = $object->getResolvedProperties();
$pvals = $object->$getResolved();
}
foreach ($pprops as $key => $value) {
foreach ($pvals as $key => $value) {
if (in_array($key, $blacklist)) continue;
if ($value !== null) {
$props[$name]->$key = $value;
$props['_MERGED_']->$key = $value;
$vals[$name]->$key = $value;
$vals['_MERGED_']->$key = $value;
if ($name !== $this->object_name) {
$vals['_INHERITED_']->$key = $value;
}
}
}
}
return $props;
return $vals;
}
protected function assertCustomVarsSupport()