2015-06-11 02:15:51 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\CustomVariable;
|
|
|
|
|
|
2015-06-11 16:44:17 -04:00
|
|
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
2016-10-14 05:53:04 -04:00
|
|
|
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
|
2015-06-11 02:15:51 -04:00
|
|
|
|
|
|
|
|
class CustomVariableString extends CustomVariable
|
|
|
|
|
{
|
|
|
|
|
public function equals(CustomVariable $var)
|
|
|
|
|
{
|
2015-10-31 19:54:43 -04:00
|
|
|
if (! $var instanceof CustomVariableString) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-11 02:15:51 -04:00
|
|
|
return $var->getValue() === $this->getValue();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-11 15:33:47 -04:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-08 18:40:07 -04:00
|
|
|
$this->deleted = false;
|
|
|
|
|
|
2015-06-11 15:33:47 -04:00
|
|
|
return $this;
|
2016-02-26 05:58:37 -05:00
|
|
|
}
|
2015-06-11 15:33:47 -04:00
|
|
|
|
2019-11-28 00:52:09 -05:00
|
|
|
public function flatten(array &$flat, $prefix)
|
2016-12-06 02:35:27 -05:00
|
|
|
{
|
|
|
|
|
// TODO: we should get rid of type=string and always use JSON
|
|
|
|
|
$flat[$prefix] = json_encode($this->getValue());
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-01 17:25:38 -04:00
|
|
|
public function toConfigString($renderExpressions = false)
|
2015-06-11 02:15:51 -04:00
|
|
|
{
|
2016-10-22 01:48:09 -04:00
|
|
|
if ($renderExpressions) {
|
2018-06-04 11:46:47 -04:00
|
|
|
return c::renderStringWithVariables($this->getValue(), ['config']);
|
2016-10-22 01:48:09 -04:00
|
|
|
} else {
|
|
|
|
|
return c::renderString($this->getValue());
|
|
|
|
|
}
|
2015-06-11 02:15:51 -04:00
|
|
|
}
|
2016-10-14 05:53:04 -04:00
|
|
|
|
|
|
|
|
public function toLegacyConfigString()
|
|
|
|
|
{
|
|
|
|
|
return c1::renderString($this->getValue());
|
|
|
|
|
}
|
2015-06-11 02:15:51 -04:00
|
|
|
}
|