summaryrefslogtreecommitdiffstats
path: root/library/Director/CustomVariable/CustomVariableBoolean.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/CustomVariable/CustomVariableBoolean.php')
-rw-r--r--library/Director/CustomVariable/CustomVariableBoolean.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/library/Director/CustomVariable/CustomVariableBoolean.php b/library/Director/CustomVariable/CustomVariableBoolean.php
new file mode 100644
index 0000000..9953fae
--- /dev/null
+++ b/library/Director/CustomVariable/CustomVariableBoolean.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Icinga\Module\Director\CustomVariable;
+
+use Icinga\Exception\ProgrammingError;
+
+class CustomVariableBoolean extends CustomVariable
+{
+ public function equals(CustomVariable $var)
+ {
+ return $var->getValue() === $this->getValue();
+ }
+
+ public function getDbFormat()
+ {
+ return 'json';
+ }
+
+ public function getDbValue()
+ {
+ return json_encode($this->getValue());
+ }
+
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ public function setValue($value)
+ {
+ if (! is_bool($value)) {
+ throw new ProgrammingError(
+ 'Expected a boolean, got %s',
+ var_export($value, 1)
+ );
+ }
+
+ $this->value = $value;
+ $this->deleted = false;
+
+ return $this;
+ }
+
+ public function toConfigString($renderExpressions = false)
+ {
+ return $this->value ? 'true' : 'false';
+ }
+
+ public function toLegacyConfigString()
+ {
+ return $this->toConfigString();
+ }
+}