From a5d7c6ccd4863b26950f9da6fdf600fca99a372e Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 28 Aug 2014 12:15:59 +0000 Subject: [PATCH] Don't use MIBEW_WEB_ROOT in get_current_locale func --- src/mibew/libs/classes/Mibew/Application.php | 14 +++++++++++++- src/mibew/libs/common/locale.php | 2 -- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Application.php b/src/mibew/libs/classes/Mibew/Application.php index 167c9e54..9bfee05e 100644 --- a/src/mibew/libs/classes/Mibew/Application.php +++ b/src/mibew/libs/classes/Mibew/Application.php @@ -104,11 +104,13 @@ class Application implements RouterAwareInterface, AuthenticationManagerAwareInt $context->fromRequest($request); $this->getRouter()->setContext($context); + // Make cookie creation easy + $cookie_factory = CookieFactory::fromRequest($request); + $authentication_manager = $this->getAuthenticationManager(); // Actualize cookie factory in the authentication manager if it is // needed. if ($authentication_manager instanceof CookieFactoryAwareInterface) { - $cookie_factory = CookieFactory::fromRequest($request); $authentication_manager->setCookieFactory($cookie_factory); } $authentication_manager->setOperatorFromRequest($request); @@ -165,6 +167,16 @@ class Application implements RouterAwareInterface, AuthenticationManagerAwareInt // him in the next requests. $authentication_manager->attachOperatorToResponse($response); + // Cache user's locale in the cookie. The code below should be treated + // as a temporary workaround. + // TODO: Move the following lines to Locales Manager when object + // oriented approach for locales will be implemented. + $response->headers->setCookie($cookie_factory->createCookie( + LOCALE_COOKIE_NAME, + get_current_locale(), + time() + 60 * 60 * 24 * 1000 + )); + return $response; } diff --git a/src/mibew/libs/common/locale.php b/src/mibew/libs/common/locale.php index cc0e7e1d..1efde4bc 100644 --- a/src/mibew/libs/common/locale.php +++ b/src/mibew/libs/common/locale.php @@ -217,8 +217,6 @@ function get_current_locale() $locale = get_user_locale(); } - setcookie(LOCALE_COOKIE_NAME, $locale, time() + 60 * 60 * 24 * 1000, MIBEW_WEB_ROOT . "/"); - $current_locale = $locale; }