diff --git a/src/mg/Ding/HttpSession/Exception/HttpSessionException.php b/src/mg/Ding/HttpSession/Exception/HttpSessionException.php new file mode 100644 index 00000000..510e0a05 --- /dev/null +++ b/src/mg/Ding/HttpSession/Exception/HttpSessionException.php @@ -0,0 +1,6 @@ +getBean('HttpViewResolver'); $exceptionMapper = $container->getBean('HttpExceptionMapper'); $render = $container->getBean('HttpViewRender'); + try { + $session = $container->getBean('SessionHandler'); + } catch(BeanFactoryException $e) { + $session = HttpSession::getSession(); + } + + if (!method_exists($session, "getSession") || !method_exists($session, "getAttribute") ) + throw new HttpSessionException("Session Handler must implement IHttpSession Interface"); + $method = strtolower($_SERVER['REQUEST_METHOD']); $url = $_SERVER['REQUEST_URI']; $urlStart = strpos($url, $baseUrl); diff --git a/src/mg/Ding/Mvc/Http/HttpViewRender.php b/src/mg/Ding/Mvc/Http/HttpViewRender.php index ac8f0e41..204a229d 100644 --- a/src/mg/Ding/Mvc/Http/HttpViewRender.php +++ b/src/mg/Ding/Mvc/Http/HttpViewRender.php @@ -34,6 +34,9 @@ use Ding\MessageSource\IMessageSourceAware; use Ding\Mvc\IViewRender; use Ding\Mvc\View; +use Ding\Container\Impl\ContainerImpl; +use Ding\HttpSession\Exception\HttpSessionException; +use Ding\Bean\Factory\Exception\BeanFactoryException; /** * Http view render. @@ -60,16 +63,25 @@ public function setMessageSource(IMessageSource $messageSource) public function translate($bundle, $message, $arguments = array()) { - $session = HttpSession::getSession(); - if (!$session->hasAttribute('LANGUAGE')) { - return $this->messageSource->getMessage( - $bundle, $message, $arguments - ); - } else { - return $this->messageSource->getMessage( - $bundle, $message, $arguments, $session->getAttribute('LANGUAGE') - ); - } + $container = ContainerImpl::getInstance(); + try { + $session = $container->getBean('SessionHandler'); + } catch(BeanFactoryException $e) { + $session = HttpSession::getSession(); + } + + if (!method_exists($session, "getSession") || !method_exists($session, "getAttribute") ) + throw new HttpSessionException("Session Handler must implement IHttpSession Interface"); + + if (!$session->hasAttribute('LANGUAGE')) { + return $this->messageSource->getMessage( + $bundle, $message, $arguments + ); + } else { + return $this->messageSource->getMessage( + $bundle, $message, $arguments, $session->getAttribute('LANGUAGE') + ); + } } /**