Commit a2aebdb0 authored by Taylor Otwell's avatar Taylor Otwell

fix routing provides bug.

parent e44eec10
...@@ -123,14 +123,13 @@ class Router { ...@@ -123,14 +123,13 @@ class Router {
foreach ($routes as $keys => $callback) foreach ($routes as $keys => $callback)
{ {
// We need to make sure that the requested format is provided by the $formats = $this->formats($callback);
// route. If it isn't, there is no need to continue evaluating it.
if ( ! in_array($format, $this->provides($callback))) continue;
// Only check routes having multiple URIs or wildcards since other // Only check the routes that couldn't be matched literally...
// routes would have been caught by the check for literal matches. if (($format_count = count($formats)) > 0 or $this->fuzzy($keys))
if (strpos($keys, '(') !== false or strpos($keys, ',') !== false)
{ {
if ($format_count > 0 and ! in_array($format, $formats)) continue;
if ( ! is_null($route = $this->match($destination, $keys, $callback, $format))) if ( ! is_null($route = $this->match($destination, $keys, $callback, $format)))
{ {
return Request::$route = $route; return Request::$route = $route;
...@@ -147,14 +146,29 @@ class Router { ...@@ -147,14 +146,29 @@ class Router {
* @param mixed $callback * @param mixed $callback
* @return array * @return array
*/ */
protected function provides($callback) protected function formats($callback)
{ {
if (is_array($callback) and isset($callback['provides'])) if (is_array($callback) and isset($callback['provides']))
{ {
return (is_string($provides = $callback['provides'])) ? explode('|', $provides) : $provides; return (is_string($provides = $callback['provides'])) ? explode('|', $provides) : $provides;
} }
return array('html'); return array();
}
/**
* Determine if a route needs to be examined using a regular expression.
*
* Routes that contain wildcards or multiple URIs cannot be matched using
* a literal key check on the array. The wildcards will have to be turned
* into real regular expressions and the multiple URIs have to be split.
*
* @param string $keys
* @return bool
*/
protected function fuzzy($keys)
{
return strpos($keys, '(') !== false or strpos($keys, ',') !== false;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment