diff options
author | Simon Rettberg | 2014-10-06 17:48:55 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-10-06 17:48:55 +0200 |
commit | 130a2d436991cc35bee5893795220b01f457a3e3 (patch) | |
tree | dff633e5156bd921f08e70ee81af1e28e8f3ac3a /inc/validator.inc.php | |
parent | Support api calls via cli by using first command line option as module name (diff) | |
download | slx-admin-130a2d436991cc35bee5893795220b01f457a3e3.tar.gz slx-admin-130a2d436991cc35bee5893795220b01f457a3e3.tar.xz slx-admin-130a2d436991cc35bee5893795220b01f457a3e3.zip |
Support list type for configuration variable
Diffstat (limited to 'inc/validator.inc.php')
-rw-r--r-- | inc/validator.inc.php | 15 |
1 files changed, 15 insertions, 0 deletions
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; + } } |