2015-10-28 22:27:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\CustomVariable;
|
|
|
|
|
|
|
|
use Icinga\Exception\ProgrammingError;
|
|
|
|
|
|
|
|
class CustomVariableNumber extends CustomVariable
|
|
|
|
{
|
|
|
|
public function equals(CustomVariable $var)
|
|
|
|
{
|
|
|
|
return $var->getValue() === $this->getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDbFormat()
|
|
|
|
{
|
|
|
|
return 'json';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValue()
|
|
|
|
{
|
|
|
|
return $this->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setValue($value)
|
|
|
|
{
|
|
|
|
if (! is_int($value) && ! is_float($value)) {
|
|
|
|
throw new ProgrammingError(
|
|
|
|
'Expected a number, got %s',
|
|
|
|
var_export($value, 1)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->value = $value;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toConfigString()
|
|
|
|
{
|
2015-11-06 09:33:42 +01:00
|
|
|
if (is_int($this->value)) {
|
|
|
|
return (string) $this->value;
|
|
|
|
} else {
|
|
|
|
// Hint: this MUST NOT respect locales
|
|
|
|
return sprintf('%F', $this->value);
|
|
|
|
}
|
2015-10-28 22:27:24 +01:00
|
|
|
}
|
|
|
|
}
|