mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-26 03:09:11 +02:00
CustomVariableNumber: new type for ints and floats
This commit is contained in:
parent
51813557c9
commit
5886765e37
42
library/Director/CustomVariable/CustomVariableNumber.php
Normal file
42
library/Director/CustomVariable/CustomVariableNumber.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?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()
|
||||||
|
{
|
||||||
|
return (string) $this->value;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user