CustomVariableNull: allow for null vars
This commit is contained in:
parent
8a72bbf513
commit
7e4067d265
|
@ -118,6 +118,10 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
|||
|
||||
public static function create($key, $value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return new CustomVariableNull($key, $value);
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
|
||||
return new CustomVariableString($key, $value);
|
||||
|
@ -137,7 +141,7 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
|||
return new CustomVariableDictionary($key, $value);
|
||||
|
||||
} else {
|
||||
throw new ProgrammingError();
|
||||
throw new ProgrammingError('WTF (%s): %s', $key, var_export($value, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\CustomVariable;
|
||||
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
class CustomVariableNull extends CustomVariable
|
||||
{
|
||||
public function equals(CustomVariable $var)
|
||||
{
|
||||
return $var->getValue() === $this->getValue();
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
if (! is_null($value)) {
|
||||
throw new ProgrammingError(
|
||||
'Null can only be null, got %s',
|
||||
var_export($value, 1)
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toConfigString()
|
||||
{
|
||||
return 'null';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue