summaryrefslogtreecommitdiff
path: root/inc/Input.class.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2012-06-24 16:54:43 +0200
committerAndreas Gohr <andi@splitbrain.org>2012-06-24 16:54:43 +0200
commita12aaeb7e914180a4c67ca7456771b6d99d9c535 (patch)
treec1ec138fe787258ea88ab1addc79c332227173cb /inc/Input.class.php
parentab5d26daf90483fc0ed3437c64011a5e8475970f (diff)
downloadrpg-a12aaeb7e914180a4c67ca7456771b6d99d9c535.tar.gz
rpg-a12aaeb7e914180a4c67ca7456771b6d99d9c535.tar.bz2
allow setting values via input class
Diffstat (limited to 'inc/Input.class.php')
-rw-r--r--inc/Input.class.php39
1 files 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
@@ -55,19 +55,29 @@ class Input {
}
/**
+ * 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
*
* This avoids copying data in memory, when the parameter is not set it will be created
* 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