diff --git a/library/Director/CustomVariable/CustomVariable.php b/library/Director/CustomVariable/CustomVariable.php index 4a824cf4..006bed11 100644 --- a/library/Director/CustomVariable/CustomVariable.php +++ b/library/Director/CustomVariable/CustomVariable.php @@ -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)); } } diff --git a/library/Director/CustomVariable/CustomVariableNull.php b/library/Director/CustomVariable/CustomVariableNull.php new file mode 100644 index 00000000..2b190cc2 --- /dev/null +++ b/library/Director/CustomVariable/CustomVariableNull.php @@ -0,0 +1,36 @@ +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'; + } +}