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
00044 parent::__construct(__CLASS__);
00045
00046
00047 $this->removeNumberFormaters();
00048 $this->removeSystemArray();
00049 }
00050
00056 public final static function createHttpRequest () {
00057
00058 $httpInstance = new HttpRequest();
00059
00060
00061 $httpInstance->prepareRequestData();
00062
00063
00064 return $httpInstance;
00065 }
00066
00074 public function prepareRequestData () {
00075
00076 $this->requestData = array_merge($_GET, $_POST);
00077 }
00078
00084 public function isRequestElementSet ($element) {
00085
00086 $isSet = isset($this->requestData[$element]);
00087
00088
00089 return $isSet;
00090 }
00091
00099 public function getRequestElement ($element) {
00100
00101 $value = null;
00102
00103
00104 if ($this->isRequestElementSet($element)) {
00105
00106 $value = $this->requestData[$element];
00107
00108
00109 $value = htmlentities(strip_tags($value), ENT_QUOTES);
00110 }
00111
00112
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
00144 $headerValue = null;
00145
00146
00147 $name = 'HTTP_' . strtolower(str_replace('-', '_', $headerName));
00148
00149
00150 if (isset($_SERVER[$name])) {
00151 $headerValue = $_SERVER[$name];
00152 }
00153
00154
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
00194 $cookieValue = null;
00195
00196
00197 if (isset($_COOKIE[$cookieName])) {
00198
00199 $cookieValue = $_COOKIE[$cookieName];
00200 }
00201
00202
00203 return $cookieValue;
00204 }
00205 }
00206
00207
00208 ?>