From a12aaeb7e914180a4c67ca7456771b6d99d9c535 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Sun, 24 Jun 2012 16:54:43 +0200 Subject: [PATCH] allow setting values via input class --- inc/Input.class.php | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/inc/Input.class.php b/inc/Input.class.php index 878f29550..aa402c646 100644 --- a/inc/Input.class.php +++ b/inc/Input.class.php @@ -54,6 +54,16 @@ class Input { return $this->access[$name]; } + /** + * Sets a parameter + * + * @param string $name Parameter name + * @param mixed $value Value to set + */ + public function set($name, $value) { + $this->access[$name] = $value; + } + /** * Get a reference to a request parameter * @@ -61,13 +71,13 @@ class Input { * and intialized with the given $default value before a reference is returned * * @param string $name Parameter name - * @param mixed $default Initialize parameter with if not set + * @param mixed $default If parameter is not set, initialize with this value * @param bool $nonempty Init with $default if parameter is set but empty() * @return &mixed */ public function &ref($name, $default = '', $nonempty = false) { if(!isset($this->access[$name]) || ($nonempty && empty($this->access[$name]))) { - $this->access[$name] = $default; + $this->set($name, $default); } $ref = &$this->access[$name]; @@ -114,7 +124,7 @@ class Input { * @param bool $nonempty Return $default if parameter is set but empty() * @return bool */ - public function bool($name, $default = '', $nonempty = false) { + public function bool($name, $default = false, $nonempty = false) { if(!isset($this->access[$name])) return $default; if($nonempty && empty($this->access[$name])) return $default; @@ -152,10 +162,22 @@ class PostInput extends Input { unset ($this->post); unset ($this->get); } + + /** + * Sets a parameter in $_POST and $_REQUEST + * + * @param string $name Parameter name + * @param mixed $value Value to set + */ + public function set($name, $value) { + parent::set($name, $value); + $_REQUEST[$name] = $value; + } } /** * Internal class used for $_GET access in Input class + */ class GetInput extends Input { protected $access; @@ -168,4 +190,15 @@ class GetInput extends Input { unset ($this->post); unset ($this->get); } + + /** + * Sets a parameter in $_GET and $_REQUEST + * + * @param string $name Parameter name + * @param mixed $value Value to set + */ + public function set($name, $value) { + parent::set($name, $value); + $_REQUEST[$name] = $value; + } } \ No newline at end of file -- GitLab