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'); + $session = $container->getBean('SessionHandler'); + $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..e6b79db4 100644 --- a/src/mg/Ding/Mvc/Http/HttpViewRender.php +++ b/src/mg/Ding/Mvc/Http/HttpViewRender.php @@ -27,13 +27,12 @@ */ namespace Ding\Mvc\Http; -use Ding\HttpSession\HttpSession; - use Ding\MessageSource\IMessageSource; use Ding\MessageSource\IMessageSourceAware; use Ding\Mvc\IViewRender; use Ding\Mvc\View; +use Ding\Container\Impl\ContainerImpl; /** * Http view render. @@ -60,16 +59,18 @@ 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(); + $session = $container->getBean('SessionHandler'); + + if (!$session->hasAttribute('LANGUAGE')) { + return $this->messageSource->getMessage( + $bundle, $message, $arguments + ); + } else { + return $this->messageSource->getMessage( + $bundle, $message, $arguments, $session->getAttribute('LANGUAGE') + ); + } } /** diff --git a/test/httpsession/Test_HttpSession.php b/test/httpsession/Test_HttpSession.php index efb88115..5b2d8055 100644 --- a/test/httpsession/Test_HttpSession.php +++ b/test/httpsession/Test_HttpSession.php @@ -27,7 +27,7 @@ * */ -use Ding\HttpSession\HttpSession; +use Ding\Container\Impl\ContainerImpl; /** * This class will test the HttpSession. @@ -43,13 +43,30 @@ */ class Test_HttpSession extends PHPUnit_Framework_TestCase { + private $_properties = array(); + + public function setUp() + { + $this->_properties = array( + 'ding' => array( + 'log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties', + 'factory' => array( + 'bdef' => array( + 'xml' => array('filename' => 'sesionHandler.xml', 'directories' => array(RESOURCES_DIR)) + ) + ) + ) + ); + } + /** * @test */ public function can_use_session() { - $session = HttpSession::getSession(); - $session->destroy(); + $container = ContainerImpl::getInstance($this->_properties); + $session = $container->getBean("SesionHandler"); + $session->destroy(); } /** @@ -57,7 +74,8 @@ public function can_use_session() */ public function can_return_false_on_invalid_attribute() { - $session = HttpSession::getSession(); + $container = ContainerImpl::getInstance($this->_properties); + $session = $container->getBean("SesionHandler"); $this->assertFalse($session->getAttribute('notexistant')); } @@ -66,7 +84,8 @@ public function can_return_false_on_invalid_attribute() */ public function can_use_attributes() { - $session = HttpSession::getSession(); + $container = ContainerImpl::getInstance($this->_properties); + $session = $container->getBean("SesionHandler"); $session->setAttribute('foo', 'bar'); $this->assertEquals($session->getAttribute('foo'), 'bar'); $this->assertTrue($session->hasAttribute('foo')); diff --git a/test/resources/sesionHandler.xml b/test/resources/sesionHandler.xml new file mode 100644 index 00000000..c400ac2f --- /dev/null +++ b/test/resources/sesionHandler.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file