class_HttpRequest.php

Go to the documentation of this file.
00001 <?php
00024 class HttpRequest extends BaseFrameworkSystem implements Requestable {
00028         private $requestData = array();
00029 
00035         private $requestIsValid = true;
00036 
00042         protected function __construct () {
00043                 // Call parent constructor
00044                 parent::__construct(__CLASS__);
00045 
00046                 // Clean up a little
00047                 $this->removeNumberFormaters();
00048                 $this->removeSystemArray();
00049         }
00050 
00056         public final static function createHttpRequest () {
00057                 // Create an instance
00058                 $httpInstance = new HttpRequest();
00059 
00060                 // Prepare the HTTP request data for usage
00061                 $httpInstance->prepareRequestData();
00062 
00063                 // Return the prepared instance
00064                 return $httpInstance;
00065         }
00066 
00074         public function prepareRequestData () {
00075                 // Copy GET then POST data
00076                 $this->requestData = array_merge($_GET, $_POST);
00077         }
00078 
00084         public function isRequestElementSet ($element) {
00085                 // Is this element found?
00086                 $isSet = isset($this->requestData[$element]);
00087 
00088                 // Return result
00089                 return $isSet;
00090         }
00091 
00099         public function getRequestElement ($element) {
00100                 // Initialize value
00101                 $value = null;
00102 
00103                 // Is the element set?
00104                 if ($this->isRequestElementSet($element)) {
00105                         // Get the bare value
00106                         $value = $this->requestData[$element];
00107 
00108                         // Secure it against attacks
00109                         $value = htmlentities(strip_tags($value), ENT_QUOTES);
00110                 } // END - if
00111 
00112                 // Return the element's value
00113                 return $value;
00114         }
00115 
00123         public function setRequestElement ($element, $value) {
00124                 $this->requestData[$element] = $value;
00125         }
00126 
00132         public function getParameterNames () {
00133                 return array_keys($this->requestData);
00134         }
00135 
00142         public function getHeader ($headerName) {
00143                 // Default return value on error
00144                 $headerValue = null;
00145 
00146                 // Construct the name
00147                 $name = 'HTTP_' . strtolower(str_replace('-', '_', $headerName));
00148 
00149                 // Does this header exist?
00150                 if (isset($_SERVER[$name])) {
00151                         $headerValue = $_SERVER[$name];
00152                 } // END - if
00153 
00154                 // Return the value
00155                 return $headerValue;
00156         }
00157 
00163         public final function getRequestMethod () {
00164                 return $_SERVER['REQUEST_METHOD'];
00165         }
00166 
00173         public final function requestIsValid ($isValid = true) {
00174                 $this->requestIsValid = (bool) $isValid;
00175         }
00176 
00182         public final function isRequestValid () {
00183                 return $this->requestIsValid;
00184         }
00185 
00192         public final function readCookie ($cookieName) {
00193                 // Default is no cookie with that name found
00194                 $cookieValue = null;
00195 
00196                 // Is the cookie set?
00197                 if (isset($_COOKIE[$cookieName])) {
00198                         // Then get it
00199                         $cookieValue = $_COOKIE[$cookieName];
00200                 } // END - if
00201 
00202                 // Return the value
00203                 return $cookieValue;
00204         }
00205 }
00206 
00207 // [EOF]
00208 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6