ENHANCEMENT Making URL accessible through HTTPRequest->getURL()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64223 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-10-14 18:47:38 +00:00
parent dcd77d065c
commit 90f3b87f35

View File

@ -16,6 +16,11 @@
*/
class HTTPRequest extends Object implements ArrayAccess {
/**
* @var string $url
*/
protected $url;
/**
* The non-extension parts of the passed URL as an array, originally exploded by the "/" separator.
* All elements of the URL are loaded in here,
@ -186,6 +191,13 @@ class HTTPRequest extends Object implements ArrayAccess {
if(isset($this->headers[$header])) unset($this->headers[$header]);
}
/**
* @return string
*/
function getURL() {
return $this->url;
}
/**
* Enables the existence of a key-value pair in the request to be checked using
* array syntax, so isset($request['title']) will check for $_POST['title'] and $_GET['title]
@ -225,13 +237,13 @@ class HTTPRequest extends Object implements ArrayAccess {
function __construct($httpMethod, $url, $getVars = array(), $postVars = array(), $body = null) {
$this->httpMethod = strtoupper(self::detect_method($httpMethod, $postVars));
$url = preg_replace(array('/\/+/','/^\//', '/\/$/'),array('/','',''), $url);
$this->url = preg_replace(array('/\/+/','/^\//', '/\/$/'),array('/','',''), $url);
if(preg_match('/^(.*)\.([A-Za-z][A-Za-z0-9]*)$/', $url, $matches)) {
$url = $matches[1];
$this->extension = $matches[2];
}
if($url) $this->dirParts = split('/+', $url);
if($this->url) $this->dirParts = split('/+', $this->url);
else $this->dirParts = array();
$this->getVars = (array)$getVars;