[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaObject: dedicated boolean munging method

git at icinga.org git at icinga.org
Tue Feb 16 12:18:11 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: b22f12cf55194afe02361f03e67d04874eb40240
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=b22f12cf55194afe02361f03e67d04874eb40240

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Feb 16 11:46:01 2016 +0100

IcingaObject: dedicated boolean munging method

---

 library/Director/Objects/IcingaObject.php |   29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 4162b6d..cfc1f4f 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -184,18 +184,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         }
 
         if ($this->propertyIsBoolean($key) && $value !== null) {
-            if ($value === 'y' || $value === '1' || $value === true || $value === 1) {
-                return parent::set($key, 'y');
-            } elseif ($value === 'n' || $value === '0' || $value === false || $value === 0) {
-                return parent::set($key, 'n');
-            } elseif ($value === '') {
-                return parent::set($key, null);
-            } else {
-                throw new ProgrammingError(
-                    'Got invalid boolean: %s',
-                    var_export($value, 1)
-                );
-            }
+            return parent::set($key, $this->normalizeBoolean($value));
         }
 
         if ($this->hasRelation($key)) {
@@ -214,6 +203,22 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         return parent::set($key, $value);
     }
 
+    protected function normalizeBoolean($value)
+    {
+        if ($value === 'y' || $value === '1' || $value === true || $value === 1) {
+            return 'y';
+        } elseif ($value === 'n' || $value === '0' || $value === false || $value === 0) {
+            return 'n';
+        } elseif ($value === '' || $value === null) {
+            return null;
+        } else {
+            throw new ProgrammingError(
+                'Got invalid boolean: %s',
+                var_export($value, 1)
+            );
+        }
+    }
+
     public function markForRemoval($remove = true)
     {
         $this->shouldBeRemoved = $remove;



More information about the icinga-checkins mailing list