From 130a2d436991cc35bee5893795220b01f457a3e3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 6 Oct 2014 17:48:55 +0200 Subject: Support list type for configuration variable --- inc/validator.inc.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'inc/validator.inc.php') diff --git a/inc/validator.inc.php b/inc/validator.inc.php index 72b7fa0b..88be14f2 100644 --- a/inc/validator.inc.php +++ b/inc/validator.inc.php @@ -18,6 +18,8 @@ class Validator case 'regex': if (preg_match($data[1], $value)) return $value; return false; + case 'list': + return self::validateList($data[1], $value); case 'function': return self::$data[1]($value); default: @@ -38,6 +40,19 @@ class Validator if (preg_match('/^\$6\$.+\$./', $value)) return $value; return Crypto::hash6($value); } + + /** + * Validate value against list. + * @param string $list The list as a string of items, separated by "|" + * @param string $value The value to validate + * @return boolean|string The value, if in list, false otherwise + */ + private static function validateList($list, $value) + { + $list = explode('|', $list); + if (in_array($value, $list)) return $value; + return false; + } } -- cgit v1.2.3-55-g7522