[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: PropertyModifierBitmask: new bitmask modifier

git at icinga.org git at icinga.org
Thu May 19 16:46:16 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed May 18 22:01:55 2016 +0200

PropertyModifierBitmask: new bitmask modifier

---

 .../PropertyModifier/PropertyModifierBitmask.php   |   35 ++++++++++++++++++++
 run.php                                            |    1 +
 2 files changed, 36 insertions(+)

diff --git a/library/Director/PropertyModifier/PropertyModifierBitmask.php b/library/Director/PropertyModifier/PropertyModifierBitmask.php
new file mode 100644
index 0000000..6eb8a14
--- /dev/null
+++ b/library/Director/PropertyModifier/PropertyModifierBitmask.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Icinga\Module\Director\PropertyModifier;
+
+use Icinga\Exception\InvalidPropertyException;
+use Icinga\Module\Director\Hook\PropertyModifierHook;
+use Icinga\Module\Director\Web\Form\QuickForm;
+
+class PropertyModifierBitmask extends PropertyModifierHook
+{
+    public static function addSettingsFormFields(QuickForm $form)
+    {
+        $form->addElement('text', 'bitmask', array(
+            'label'       => 'Bitmask',
+            'description' => $form->translate(
+                'The numeric bitmask you want to apply. In case you have a hexadecimal'
+                . ' or binary mask please transform it to a deximal number first. The'
+                . ' result of this modifier is a boolean value, telling whether the'
+                . ' given mask applies to the numeric value in your source column'
+            ),
+            'required'    => true,
+        ));
+    }
+
+    public function getName()
+    {
+        return 'Bitmask match (numeric)';
+    }
+
+    public function transform($value)
+    {
+        $mask = (int) $this->getSetting('bitmask');
+        return (((int) $value) & $mask) === $mask;
+    }
+}
diff --git a/run.php b/run.php
index 0117072..c3e770d 100644
--- a/run.php
+++ b/run.php
@@ -31,6 +31,7 @@ $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\Pro
 $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierExtractFromDN');
 $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierFromAdSid');
 $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierFromLatin1');
+$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierBitmask');
 
 $this->provideHook('director/Job', $prefix . 'Job\\HousekeepingJob');
 $this->provideHook('director/Job', $prefix . 'Job\\ConfigJob');



More information about the icinga-checkins mailing list