diff --git a/Request.inc.php b/Request.inc.php index ccce95f..23b786c 100644 --- a/Request.inc.php +++ b/Request.inc.php @@ -1,6 +1,168 @@ getBody(); + case 'headers': + return $this->getHeaders(); + case 'method': + return $this->getMethod(); + case 'path': + return $this->getPath(); + case 'pathParts': + return $this->getPathParts(); + case 'query': + return $this->getQuery(); + default: + throw new Exception('Property ' . $name . ' does not exist.'); + } + + } + + public function getBody() { + return $this->body; + } + + public function getHeaders() { + return $this->headers; + } + + public function getMethod() { + return $this->method; + } + + public function getPath() { + return $this->path; + } + + public function getPathParts() { + return $this->pathParts; + } + + public function getQuery() { + return $this->query; + } + + + // ------------------------------------------------------------------------- + + /** + * Set instance members based on the HTTP request sent to the server. + */ + public function readHttpRequest() { + + $this->body = file_get_contents("php://input"); + + $this->headers = apache_request_headers(); + + $this->method = $_SERVER['REQUEST_METHOD']; + + $uri = parse_url($_SERVER['REQUEST_URI']); + $this->path = $uri['path']; + + $this->pathParts = explode('/', substr($this->path, 1)); + + $this->query = $_GET; + + } // readHttpRequest() + + /** + * Return a reference to the singleton instance of the Request derived + * from the server's information about the request sent to the script. + * + * @return Request + * @static + */ + static public function getRequest() { + + if (!isset(self::$theRequest)) { + + $klass = __CLASS__; + $request = new $klass(); + $request->readHttpRequest(); + + self::$theRequest = $request; + + } + + return self::$theRequest; + + } // getRequest() } diff --git a/Response.inc.php b/Response.inc.php index f660683..ecfa30c 100644 --- a/Response.inc.php +++ b/Response.inc.php @@ -1,5 +1,7 @@