From 7266b41aded2db6a88f980431752f25688cb204b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 23:01:31 +0200 Subject: [PATCH] [FrameworkBundle] added the current locale as the default value for _locale when generating routes --- .../FrameworkBundle/RequestListener.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php index 80eec52471..ac68a2e57c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php @@ -77,14 +77,20 @@ class RequestListener if ($master) { // set the context even if the parsing does not need to be done // to have correct link generation - $this->router->setContext(new RequestContext( + $context = new RequestContext( $request->getBaseUrl(), $request->getMethod(), $request->getHost(), $request->getScheme(), $this->httpPort, $this->httpsPort - )); + ); + + if ($session = $request->getSession()) { + $context->setParameter('_locale', $session->getLocale()); + } + + $this->router->setContext($context); } if ($request->attributes->has('_controller')) { @@ -101,10 +107,6 @@ class RequestListener } $request->attributes->add($parameters); - - if ($locale = $request->attributes->get('_locale')) { - $request->getSession()->setLocale($locale); - } } catch (NotFoundException $e) { $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo()); if (null !== $this->logger) { @@ -118,6 +120,11 @@ class RequestListener } throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e); } + + if ($master && $locale = $request->attributes->get('_locale')) { + $request->getSession()->setLocale($locale); + $context->setParameter('_locale', $locale); + } } private function parametersToString(array $parameters)