Source for file Request.class.php
Documentation is available at Request.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @desc Http Request Class
gumbo_load ("Interface_Singleton");
gumbo_load ("Interface_Http_Request");
gumbo_load ("Http_Input");
class Gumbo_Http_Request implements Gumbo_Interface_Http_Request, Gumbo_Interface_Singleton {
/** @var Gumbo_Interface_Http_Request $_instance */
private static $_instance =
null;
/** @var string $_method HTTP request method */
/** @var string $_mode get mode */
/** @var array $_fields list of fields that have been checked */
/** @var array $_map map of REQUEST data */
$this->_method =
$_SERVER ['REQUEST_METHOD'];
// sets all data to 'raw'
* Singleton Pattern Method
* @return Gumbo_Interface_Http_Request
if (self::$_instance ==
null) {
self::$_instance =
new Gumbo_Http_Request ();
* Returns the value of the $_REQUEST field based on the mode
public function __get ($fld) {
return $this->get ($fld);
* Returns if the field exists in the REQUEST array
return isset
($_REQUEST [$fld]);
* Validates the $_REQUEST variable Constraints (if null, validates all)
* @throws Gumbo_Exception
public function validate ($field=
null) {
if (!is_null ($field) &&
!is_string ($field)) {
// validates ALL fields through recursion
// loop through Constraints, if any
$status =
$input->toIgnoreConstraints ();
if ($input->hasInput ($field)) {
$input->$field->setData ($this->getRaw ($field));
$status =
$input->$field->clean ();
$e->setFunction (__METHOD__
);
* Adds a status to the $_REQUEST field
* @throws Gumbo_Exception
if (!isset
($this->$field)) {
$e->setFunction (__METHOD__
);
* Sets the default return mode (request|cookie|post|get)
* @throws Gumbo_Exception
default : throw
new Gumbo_Exception ("Invalid Argument 'mode:request|cookie|post|get' => {$mode}");
$e->setFunction (__METHOD__
);
* Sets a status code for a $_REQUEST field
* @param string $code status code [raw|dirty|clean]
* @throws Gumbo_Exception
protected function setField ($field, $code) {
if (!isset
($this->$field)) {
if ($code !=
"raw" &&
$code !=
"dirty" &&
$code !=
"clean") {
throw
new Gumbo_Exception ("Invalid Argument 'code:raw|dirty|clean' => {$code}");
$e->setFunction (__METHOD__
);
* Returns the value of the $_REQUEST field
* @throws Gumbo_Exception
public function get ($field, $mode=
null) {
if (!isset
($this->$field)) {
$data =
$this->getRaw ($field, $mode);
// verify data can be sent
if (!$input->toIgnoreConstraints ()) {
if ($this->getField ($field) ==
"raw") {
if (!$status ||
$status ==
"dirty" ||
$status ==
"raw") {
throw
new Gumbo_Exception ("REQUEST Data Failed Input Constraints: {$field}");
// filter the data through Constraints
if ($input->hasInput ($field)) {
if ($input->$field->isClean ()) {
$data =
$input->$field->getData ();
$e->setFunction (__METHOD__
);
* Returns the raw data value from $_REQUEST, $_POST, $_GET, or $_COOKIE
* @throws Gumbo_Exception
protected function getRaw ($field, $mode=
null) {
if (!isset
($this->$field)) {
if ($mode !=
"request" &&
$mode !=
"cookie" &&
$mode !=
"post" &&
$mode !=
"get") {
case "request" :
if (isset
($_REQUEST [$field])) { $val =
$_REQUEST [$field]; } break;
case "cookie" :
if (isset
($_COOKIE [$field])) { $val =
$_COOKIE [$field]; } break;
case "post" :
if (isset
($_POST [$field])) { $val =
$_POST [$field]; } break;
case "get" :
if (isset
($_GET [$field])) { $val =
$_GET [$field]; } break;
$e->setFunction (__METHOD__
);
* Returns an array map of User Input
* @param bool $reload reloads the map
* @throws Gumbo_Exception
public function getMap ($reload=
false) {
$e->setFunction (__METHOD__
);
// check if the map was previously created
$this->_map [$val] =
$this->get ($val);
* Returns the HTTP request method
* Returns the mode return values will be retrieved from
* Returns the status of the $_REQUEST field
* @throws Gumbo_Exception
if (!isset
($this->$field)) {
$e->setFunction (__METHOD__
);
* Returns all the fields status codes
* Returns if the field has been registered
* @throws Gumbo_Exception
protected function isField ($field) {
if (!isset
($this->$field)) {
return isset
($this->_fields [$field]);
$e->setFunction (__METHOD__
);