Improved support for page parameters

The get method accepts a default value/exception to be thrown if the requested variable does not exist (similar semantics to HBC_Main::isset)
The last request string component is stripped if it is empty
The last request string variable is now given default value of true if no value is specified
This commit is contained in:
2010-03-23 01:56:50 +00:00
parent ddbaf0022b
commit 8caf48f53b

View File

@@ -58,7 +58,13 @@ class HandBrakeCluster_RequestParser {
// The subsequent tokens are parameters for this page in key value pairs // The subsequent tokens are parameters for this page in key value pairs
while ($components) { while ($components) {
$this->vars[array_shift($components)] = $components ? array_shift($components) : null; // If the url ended with a trailing slash, the last element will be null
$last_element = $components[count($components) - 1];
if ($last_element == "") {
array_pop($components);
}
$this->vars[array_shift($components)] = $components ? array_shift($components) : true;
} }
} }
@@ -66,12 +72,16 @@ class HandBrakeCluster_RequestParser {
return join('/', $this->page); return join('/', $this->page);
} }
public function get($key) { public function get($key, $default = null) {
if (isset($this->vars[$key])) { if (isset($this->vars[$key])) {
return $this->vars[$key]; return $this->vars[$key];
} }
return null; if (is_subclass_of($default, HandBrakeCluster_Exception)) {
throw new $default();
}
return $default;
} }
public function request_string() { public function request_string() {