Permalink
Browse files

API Adding setURL to HTTPRequest object

The current RootURLController needs to be able to change the url of a
request, so I've added it.
  • Loading branch information...
1 parent 3457f43 commit 9258485aeb3fe7fac81b4232f3c7516c78b1d18a @dhensby dhensby committed Feb 27, 2013
Showing with 21 additions and 5 deletions.
  1. +21 −5 control/HTTPRequest.php
View
@@ -104,6 +104,24 @@ class SS_HTTPRequest implements ArrayAccess {
*/
public function __construct($httpMethod, $url, $getVars = array(), $postVars = array(), $body = null) {
$this->httpMethod = strtoupper(self::detect_method($httpMethod, $postVars));
+ $this->setUrl($url);
+
+ $this->getVars = (array)$getVars;
+ $this->postVars = (array)$postVars;
+ $this->body = $body;
+ }
+
+ /**
+ * Allow the setting of a URL
+ *
+ * This is here so that RootURLController can change the URL of the request
+ * without us loosing all the other info attached (like headers)
+ *
+ * @param string The new URL
+ *
+ * @return SS_HTTPRequest The updated request
+ */
+ public function setUrl($url) {
$this->url = $url;
// Normalize URL if its relative (strictly speaking), or has leading slashes
@@ -116,10 +134,8 @@ public function __construct($httpMethod, $url, $getVars = array(), $postVars = a
}
if($this->url) $this->dirParts = preg_split('|/+|', $this->url);
else $this->dirParts = array();
-
- $this->getVars = (array)$getVars;
- $this->postVars = (array)$postVars;
- $this->body = $body;
+
+ return $this;
}
/**
@@ -610,7 +626,7 @@ public function shift($count = 1) {
for($i=0;$i<$count;$i++) {
$value = array_shift($this->dirParts);
- if(!$value) break;
+ if($value === null) break;
$return[] = $value;
}

0 comments on commit 9258485

Please sign in to comment.