/** * Constructor. * It builds the HTTPRequest object * * @todo a URI Helper should be written. * @todo a Cookie class should be written. */ public function HTTPRequest() { $this->method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET'; foreach (array_merge($_GET, $_POST) as $key => $value) { $this->setParameter($key, $value); } foreach ($_COOKIE as $cookie_name => $cookie_value) { $this->cookies[$cookie_name] = new Cookie($cookie_name, $cookie_value); } unset($_REQUEST); unset($_GET); unset($_POST); if (array_key_exists('PATH_INFO', $_SERVER) && $_SERVER['PATH_INFO'] != '') { $this->requestUri = $_SERVER['PATH_INFO']; } elseif (array_key_exists('REQUEST_URI', $_SERVER)) { $this->requestUri = substr($_SERVER['REQUEST_URI'], 7); } $this->session = new Session(); $this->headers = HTTPRequest::getAllHeaders(); }
/** * It builds the HTTPRequest object */ public function HTTPRequest() { $this->method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET'; foreach (array_merge($_GET, $_POST) as $key => $value) { $this->setParameter($key, $value); } foreach ($_COOKIE as $cookie_name => $cookie_value) { $this->cookies[$cookie_name] = new Cookie($cookie_name, $cookie_value); } unset($_REQUEST); unset($_GET); unset($_POST); // setup requestUri if (array_key_exists('PATH_INFO', $_SERVER) && $_SERVER['PATH_INFO'] != '') { $this->requestUri = $_SERVER['PATH_INFO']; } elseif (array_key_exists('ORIG_PATH_INFO', $_SERVER)) { // todo: it should be also tested for non root locations eg: // http://www.example.com/foo/medick/myapplication/project/create.html // should substract only /project/create.html! // even if we don't use rewrite mode (rewrite=off in config file) this should work. $this->requestUri = $_SERVER['ORIG_PATH_INFO']; } else { // fallback to REQUEST_URI $this->requestUri = substr($_SERVER['REQUEST_URI'], 7); } $this->session = new Session(); $this->headers = HTTPRequest::getAllHeaders(); }