IcingaConfigHelper: add reserved words

This commit is contained in:
Thomas Gelf 2015-06-11 07:52:26 +02:00
parent 9e52629d6e
commit 38221e0605
2 changed files with 45 additions and 3 deletions

View File

@ -4,6 +4,37 @@ namespace Icinga\Module\Director;
class IcingaConfigHelper
{
/**
* Reserved words according to
* http://docs.icinga.org/icinga2/snapshot/doc/module/icinga2/chapter/language-reference#reserved-keywords
*/
protected static $reservedWords = array(
'object',
'template',
'include',
'include_recursive',
'library',
'null',
'true',
'false',
'const',
'var',
'this',
'use',
'apply',
'to',
'where',
'import',
'assign',
'ignore',
'function',
'return',
'for',
'if',
'else',
'in',
);
public static function renderKeyValue($key, $value, $prefix = '')
{
return sprintf(
@ -32,4 +63,18 @@ class IcingaConfigHelper
return sprintf('"%s"', $string);
}
public static function isReserved($string)
{
return in_array($string, self::$reservedWords);
}
public static function escapeIfReserved($string)
{
if (self::isReserved($string)) {
return '@' . $string;
} else {
return $string;
}
}
}

View File

@ -91,9 +91,6 @@ abstract class IcingaObject extends DbObject
}
/**
* TODO: take care for reserved words, because we need them escaped
* http://docs.icinga.org/icinga2/snapshot/doc/module/icinga2/chapter/language-reference#reserved-keywords
*
* @return string
*/
protected function renderCustomVars()