diff --git a/include/class.dispatcher.php b/include/class.dispatcher.php index 44d710b55b1256bfe5709c0ddc0254a80695031a..0448f5024eb3e9244f1bf1bbe1b8b462d171117a 100644 --- a/include/class.dispatcher.php +++ b/include/class.dispatcher.php @@ -100,9 +100,11 @@ class UrlMatcher { } function dispatch($url, $prev_args=null) { + # Remove named values from the match array - $this->matches = array_flip(array_intersect( - array_flip($this->matches), range(0,31))); + $f = array_filter(array_keys($this->matches), 'is_numeric'); + $this->matches = array_intersect_key($this->matches, array_flip($f)); + if (@get_class($this->func) == "Dispatcher") { # Trim the leading match off the $url and call the # sub-dispatcher. This will be the case for lines in the URL @@ -116,29 +118,31 @@ class UrlMatcher { substr($url, strlen($this->matches[0])), array_merge(($prev_args) ? $prev_args : array(), array_slice($this->matches, 1))); - } else { - # Drop the first item of the matches array (which is the whole - # matched url). Then merge in any initial arguments. - unset($this->matches[0]); - # Prepend received arguments (from a parent Dispatcher). This is - # different from the static args, which are postpended - if (is_array($prev_args)) - $args = array_merge($prev_args, $this->matches); - else $args = $this->matches; - # Add in static args specified in the constructor - $args = array_merge($args, $this->args); - # Apply the $prefix given - list($class, $func) = $this->apply_prefix(); - if ($class) { - # Create instance of the class, which is the first item, - # then call the method which is the second item - $func = array(new $class, $func); - } - if (!is_callable($func)) - Http::response(500, - 'Dispatcher compile error. Function not callable'); - return call_user_func_array($func, $args); } + + # Drop the first item of the matches array (which is the whole + # matched url). Then merge in any initial arguments. + unset($this->matches[0]); + + # Prepend received arguments (from a parent Dispatcher). This is + # different from the static args, which are postpended + if (is_array($prev_args)) + $args = array_merge($prev_args, $this->matches); + else $args = $this->matches; + # Add in static args specified in the constructor + $args = array_merge($args, $this->args); + # Apply the $prefix given + list($class, $func) = $this->apply_prefix(); + if ($class) { + # Create instance of the class, which is the first item, + # then call the method which is the second item + $func = array(new $class, $func); + } + + if (!is_callable($func)) + Http::response(500, 'Dispatcher compile error. Function not callable'); + + return call_user_func_array($func, $args); } /** * For the $prefix recieved by the constuctor, prepend it to the