From 0d930efb46b69a8f3bc26a204229cd76a644cd89 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 13 Oct 2016 07:54:31 +0000 Subject: [PATCH] IcingaObject: add new resolving helper methods This for example allows to get a single inherited var and their origin --- library/Director/Objects/IcingaObject.php | 46 ++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 6f0f0d7f..d68a0305 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -421,7 +421,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer $this->resolveUnresolvedRelatedProperties(); if ($this->supportsCustomVars() && $this->vars !== null && $this->vars()->hasBeenModified()) { -//var_dump($this->vars()); exit; return true; } @@ -798,6 +797,51 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $default; } + public function getInheritedProperty($key, $default = null) + { + if (array_key_exists($key, $this->unresolvedRelatedProperties)) { + $this->resolveUnresolvedRelatedProperty($key); + $this->invalidateResolveCache(); + } + + $properties = $this->getInheritedProperties(); + if (property_exists($properties, $key)) { + return $properties->$key; + } + + return $default; + } + + public function getInheritedVar($varname) + { + try { + $vars = $this->getInheritedVars(); + } catch (NestingError $e) { + return null; + } + + if (property_exists($vars, $varname)) { + return $vars->$varname; + } else { + return null; + } + } + + public function getOriginForVar($varname) + { + try { + $origins = $this->getOriginsVars(); + } catch (NestingError $e) { + return null; + } + + if (property_exists($origins, $varname)) { + return $origins->$varname; + } else { + return null; + } + } + public function getResolvedProperties() { return $this->getResolved('Properties');