reimplement locale uri slugs.

This commit is contained in:
Taylor Otwell
2012-08-20 10:46:23 -05:00
parent 7298c93be1
commit 926cdaa7f5
3 changed files with 71 additions and 6 deletions

View File

@@ -107,6 +107,48 @@ Routing\Router::register('*', '(:all)', function()
return Event::first('404');
});
/*
|--------------------------------------------------------------------------
| Gather The URI And Locales
|--------------------------------------------------------------------------
|
| When routing, we'll need to grab the URI and the supported locales for
| the route so we can properly set the language and route the request
| to the proper end-point in the application.
|
*/
$uri = URI::current();
$languages = Config::get('application.languages', array());
$languages[] = Config::get('application.language');
/*
|--------------------------------------------------------------------------
| Set The Locale Based On The Route
|--------------------------------------------------------------------------
|
| If the URI starts with one of the supported languages, we will set
| the default lagnauge to match that URI segment and shorten the
| URI we'll pass to the router to not include the lang segment.
|
*/
foreach ($languages as $language)
{
if (starts_with($uri, $language))
{
Config::set('application.language', $language);
$uri = trim(substr($uri, strlen($language)), '/'); break;
}
}
if ($uri == '') $uri = '/';
URI::$uri = $uri;
/*
|--------------------------------------------------------------------------
| Route The Incoming Request
@@ -118,8 +160,6 @@ Routing\Router::register('*', '(:all)', function()
|
*/
$uri = URI::current();
Request::$route = Routing\Router::route(Request::method(), $uri);
$response = Request::$route->call();