diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-04-30 20:08:42 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-04-30 20:08:42 +0200 |
commit | 9d303680c2a8a5242c7583dc2f45ebd51f59409d (patch) | |
tree | 485c1f87435b158c68801b2fae090343dba5ce3e /inc | |
parent | 363404184fcd4ec7b0149662d99a22f2cc78020b (diff) | |
parent | 61ee3dfc9d16c60348b3b40051e8fc898b09bc8b (diff) | |
download | rpg-9d303680c2a8a5242c7583dc2f45ebd51f59409d.tar.gz rpg-9d303680c2a8a5242c7583dc2f45ebd51f59409d.tar.bz2 |
Merge pull request #669 from splitbrain/validinputs
#667 - directly get a valid INPUT parameter
Diffstat (limited to 'inc')
-rw-r--r-- | inc/Input.class.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/inc/Input.class.php b/inc/Input.class.php index de8bf5b97..e7eef1c29 100644 --- a/inc/Input.class.php +++ b/inc/Input.class.php @@ -144,6 +144,26 @@ class Input { } /** + * Access a request parameter and make sure it is has a valid value + * + * Please note that comparisons to the valid values are not done typesafe (request vars + * are always strings) however the function will return the correct type from the $valids + * array when an match was found. + * + * @param string $name Parameter name + * @param array $valids Array of valid values + * @param mixed $default Default to return if parameter isn't set or not valid + * @return null|mixed + */ + public function valid($name, $valids, $default = null) { + if(!isset($this->access[$name])) return $default; + if(is_array($this->access[$name])) return $default; // we don't allow arrays + $found = array_search($this->access[$name], $valids); + if($found !== false) return $valids[$found]; // return the valid value for type safety + return $default; + } + + /** * Access a request parameter as bool * * Note: $nonempty is here for interface consistency and makes not much sense for booleans |