diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
commit | cd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/CustomVariable/CustomVariableString.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip |
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/CustomVariable/CustomVariableString.php')
-rw-r--r-- | library/Director/CustomVariable/CustomVariableString.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/library/Director/CustomVariable/CustomVariableString.php b/library/Director/CustomVariable/CustomVariableString.php new file mode 100644 index 0000000..2d50968 --- /dev/null +++ b/library/Director/CustomVariable/CustomVariableString.php @@ -0,0 +1,59 @@ +<?php + +namespace Icinga\Module\Director\CustomVariable; + +use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; +use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; + +class CustomVariableString extends CustomVariable +{ + public function equals(CustomVariable $var) + { + if (! $var instanceof CustomVariableString) { + return false; + } + + return $var->getValue() === $this->getValue(); + } + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + if (! is_string($value)) { + $value = (string) $value; + } + + if ($value !== $this->value) { + $this->value = $value; + $this->setModified(); + } + + $this->deleted = false; + + return $this; + } + + public function flatten(array &$flat, $prefix) + { + // TODO: we should get rid of type=string and always use JSON + $flat[$prefix] = json_encode($this->getValue()); + } + + public function toConfigString($renderExpressions = false) + { + if ($renderExpressions) { + return c::renderStringWithVariables($this->getValue(), ['config']); + } else { + return c::renderString($this->getValue()); + } + } + + public function toLegacyConfigString() + { + return c1::renderString($this->getValue()); + } +} |