IcingaObject: add initial resolve methods

This commit is contained in:
Thomas Gelf 2015-07-02 14:51:59 +02:00
parent 410d06dc63
commit edad30f0ac
1 changed files with 49 additions and 0 deletions

View File

@ -31,6 +31,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
private $imports;
private $importedObjects;
private $ranges;
public function supportsCustomVars()
@ -116,6 +118,53 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->imports;
}
// TODO: what happens if imports change at runtime?
public function importedObjects()
{
$this->assertImportsSupport();
if ($this->importedObjects === null) {
$this->importedObjects = array();
foreach ($this->imports()->listImportNames() as $import) {
$this->importedObjects[$import] = self::load($import, $this->connection);
}
}
return $this->importedObjects;
}
public function getResolvedProperties()
{
$res = $this->resolveProperties();
return $res['_MERGED_'];
}
public function resolveProperties()
{
$props = array();
$props['_MERGED_'] = (object) array();
$objects = $this->importedObjects();
$objects[$this->object_name] = $this;
$blacklist = array('id', 'object_type', 'object_name');
foreach ($objects as $name => $object) {
$props[$name] = (object) array();
if ($name === $this->object_name) {
$pprops = $object->getProperties();
} else {
$pprops = $object->getResolvedProperties();
}
foreach ($pprops as $key => $value) {
if (in_array($key, $blacklist)) continue;
if ($value !== null) {
$props[$name]->$key = $value;
$props['_MERGED_']->$key = $value;
}
}
}
return $props;
}
protected function assertCustomVarsSupport()
{
if (! $this->supportsCustomVars()) {