[icinga-checkins] icinga.org: icingaweb2-module-director/feature/icinga1-config-12919: IcingaObject: add new resolving helper methods

git at icinga.org git at icinga.org
Fri Oct 14 15:36:04 CEST 2016


Module: icingaweb2-module-director
Branch: feature/icinga1-config-12919
Commit: 0d930efb46b69a8f3bc26a204229cd76a644cd89
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=0d930efb46b69a8f3bc26a204229cd76a644cd89

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Oct 13 07:54:31 2016 +0000

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 6f0f0d7..d68a030 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');



More information about the icinga-checkins mailing list