8000 [FrameworkBundle] fixed _locale management in core.request · DerekRoth/symfony@8457bfa · GitHub
[go: up one dir, main page]

Skip to content

Commit 8457bfa

Browse files
committed
[FrameworkBundle] fixed _locale management in core.request
1 parent c72537d commit 8457bfa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ public function onEarlyCoreRequest(GetResponseEvent $event)
6161
$request->isSecure() ? $request->getPort() : $this->httpsPort
6262
);
6363

64-
if ($session = $request->getSession()) {
65-
$context->setParameter('_locale', $session->getLocale());
66-
}
67-
6864
$this->router->setContext($context);
6965
}
7066

@@ -100,9 +96,17 @@ public function onCoreRequest(GetResponseEvent $event)
10096
throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
10197
}
10298

103-
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType() && $locale = $request->attributes->get('_locale')) {
104-
$request->getSession()->setLocale($locale);
105-
$this->router->getContext()->setParameter('_locale', $locale);
99+
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
100+
$context = $this->router->getContext();
101+
$session = $request->getSession();
102+
if ($locale = $request->attributes->get('_locale')) {
103+
if ($session) {
104+
$session->setLocale($locale);
105+
}
106+
$context->setParameter('_locale', $locale);
107+
} elseif ($session) {
108+
$context->setParameter('_locale', $session->getLocale());
109+
}
106110
}
107111
}
108112

0 commit comments

Comments
 (0)
0