From 74887986a70318dc5b333ce7aebda872116ddbbe Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 12 Feb 2012 19:26:16 -0600 Subject: [PATCH] fixing bugs in router. --- laravel/bundle.php | 6 ++++-- laravel/routing/router.php | 38 ++++++++++++-------------------------- laravel/url.php | 4 +++- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/laravel/bundle.php b/laravel/bundle.php index 6e683b43..8770a049 100644 --- a/laravel/bundle.php +++ b/laravel/bundle.php @@ -107,6 +107,8 @@ public static function start($bundle) */ public static function routes($bundle) { + if (static::routed($bundle)) return; + $path = static::path($bundle).'routes'.EXT; // By setting the bundle property on the router the router knows what @@ -116,10 +118,10 @@ public static function routes($bundle) if ( ! static::routed($bundle) and file_exists($path)) { + static::$routed[] = $bundle; + require $path; } - - static::$routed[] = $bundle; } /** diff --git a/laravel/routing/router.php b/laravel/routing/router.php index 6991f1f4..c99dc0d5 100644 --- a/laravel/routing/router.php +++ b/laravel/routing/router.php @@ -367,11 +367,14 @@ public static function find($name) // To find a named route, we will iterate through every route defined // for the application. We will cache the routes by name so we can // load them very quickly the next time. - foreach (static::all() as $key => $value) + foreach (static::routes() as $method => $routes) { - if (array_get($value, 'name') === $name) + foreach ($routes as $key => $value) { - return static::$names[$name] = array($key => $value); + if (isset($value['name']) and $value['name'] === $name) + { + return static::$names[$name] = array($key => $value); + } } } } @@ -397,11 +400,14 @@ public static function uses($action) // To find the route, we'll simply spin through the routes looking // for a route with a "uses" key matching the action, and if we // find one we cache and return it. - foreach (static::all() as $uri => $route) + foreach (static::routes() as $method => $routes) { - if (array_get($route, 'uses') == $action) + foreach ($routes as $key => $value) { - return static::$uses[$action] = array($uri => $route); + if (isset($value['uses']) and $value['uses'] === $action) + { + return static::$uses[$action] = array($key => $value); + } } } } @@ -490,26 +496,6 @@ protected static function wildcards($key) return strtr($key, static::$patterns); } - /** - * Get all of the routes across all request methods. - * - * @return array - */ - public static function all() - { - $all = array(); - - // To get all the routes, we'll just loop through each request - // method supported by the router and merge in each of the - // arrays into the main array of routes. - foreach (static::$methods as $method) - { - $all = array_merge($all, static::routes($method)); - } - - return $all; - } - /** * Get all of the registered routes, with fallbacks at the end. * diff --git a/laravel/url.php b/laravel/url.php index d3f9ee5c..55cce516 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -244,7 +244,9 @@ public static function to_route($name, $parameters = array()) // should be generated with an HTTPS protocol string or just HTTP. $https = array_get(current($route), 'https', false); - return static::to(static::transpose(key($route), $parameters), $https); + $uri = trim(static::transpose(key($route), $parameters), '/'); + + return static::to($uri, $https); } /**