Add Request::Filter and ::FilterArray.
authorRobert Sesek <rsesek@bluestatic.org>
Wed, 27 May 2015 04:22:54 +0000 (00:22 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Wed, 27 May 2015 04:22:54 +0000 (00:22 -0400)
http/request.php

index ff48b00ff1ad686903656760e3ac36ebcd9cb3bd..031518b0c68b3e7e025b432fffd045a03cd9e7ce 100644 (file)
@@ -40,4 +40,24 @@ class Request extends \hoplite\base\StrictObject
   {
     $this->url = $url;
   }
+
+  /*!
+    Wrapper around filter_input() that stores the result in the ::$data field.
+   */
+  public function Filter($type, $name, $filter=FILTER_SANITIZE_STRING, $options=NULL)
+  {
+    $rv = filter_input($type, $name, $filter, $options);
+    $this->data[$name] = $rv;
+    return $rv;
+  }
+
+  /*!
+    Wrapper around filter_input() that merges the result in the ::$data field.
+   */
+  public function FilterArray($type, $definition, $add_empty=TRUE)
+  {
+    $rv = filter_input_array($type, $definition, $add_empty);
+    $this->data = array_merge($this->data, $rv);
+    return $rv;
+  }
 }