From 1418498c406caca058076e3d148e31daee800551 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 6 Mar 2014 14:54:19 +0000 Subject: extend to cover (PR#589) --- inc/Input.class.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'inc/Input.class.php') diff --git a/inc/Input.class.php b/inc/Input.class.php index 7434d2b2c..de8bf5b97 100644 --- a/inc/Input.class.php +++ b/inc/Input.class.php @@ -15,6 +15,8 @@ class Input { public $post; /** @var GetInput Access $_GET parameters */ public $get; + /** @var ServerInput Access $_SERVER parameters */ + public $server; protected $access; @@ -25,6 +27,7 @@ class Input { $this->access = &$_REQUEST; $this->post = new PostInput(); $this->get = new GetInput(); + $this->server = new ServerInput(); } /** @@ -260,3 +263,18 @@ class GetInput extends Input { $_REQUEST[$name] = $value; } } + +/** + * Internal class used for $_SERVER access in Input class + */ +class ServerInput extends Input { + protected $access; + + /** + * Initialize the $access array, remove subclass members + */ + function __construct() { + $this->access = &$_SERVER; + } + +} -- cgit v1.2.3 From 6920d2fd3e30c9cb3abd500fe18273974da7182f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 30 Apr 2014 19:44:50 +0200 Subject: add new valid() method to $INPUT #667 --- inc/Input.class.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'inc/Input.class.php') 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 @@ -143,6 +143,26 @@ class Input { return (string) $this->access[$name]; } + /** + * 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 * -- cgit v1.2.3