CustomVariableNull: allow for null vars

This commit is contained in:
Thomas Gelf 2015-08-28 18:13:01 +02:00
parent 8a72bbf513
commit 7e4067d265
2 changed files with 41 additions and 1 deletions

View File

@ -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));
}
}

View File

@ -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';
}
}