/** * @test */ public function can_use_attributes() { $session = HttpSession::getSession(); $session->setAttribute('foo', 'bar'); $this->assertEquals($session->getAttribute('foo'), 'bar'); $this->assertTrue($session->hasAttribute('foo')); }
public function changeLanguageAction($language) { $session = HttpSession::getSession(); $session->setAttribute('LANGUAGE', $language); $modelAndView = new RedirectModelAndView('/'); return $modelAndView; }
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')); } }
public function someAction() { $session = HttpSession::getSession(); $session->setAttribute('aSessionVariable', array('user' => 'aUser')); $modelAndView = new ModelAndView('some'); $modelAndView->add(array('somestring' => 'Hello World', 'arguments' => func_get_args())); $modelAndView->add(array('headers' => array('Cache-Control: no-cache', 'Pragma: no-cache'))); return $modelAndView; }
/** * @test */ public function can_render_and_translate() { // For language stuff ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . RESOURCES_DIR); $this->expectOutputString('hi there'); $mav = new ModelAndView('some'); $mav->add(array('headers' => array('HTTP/1.0 404 Not Found'))); $container = ContainerImpl::getInstance($this->_properties); $resolver = $container->getBean('HttpViewResolver3'); $view = $resolver->resolve($mav); $render = $container->getBean('HttpViewRender'); $render->render($view); $this->assertEquals($render->translate('abundle', 'message.some', array('arg1' => '1', 'arg2' => '2', 'arg3' => '3')), 'This is a test message, arg1=1 arg2=2 arg3=3'); $session = HttpSession::getSession(); $session->setAttribute('LANGUAGE', 'es_AR'); $this->assertEquals($render->translate('abundle', 'message.some', array('arg1' => '1', 'arg2' => '2', 'arg3' => '3')), 'Este es un mensaje de prueba, arg1=1 arg2=2 arg3=3'); }
/** * Handles the request. This will instantiate the container with the given * properties (via static method configure(), see below). Then it will * getBean(HttpDispatcher) and call dispatch() on it with an Action created * based on the request uri and method parameters (get, post, etc). * * @return void */ public static function handle(array $properties = array(), $baseUrl = '/') { $exceptionThrown = null; $filtersPassed = true; $session = HttpSession::getSession(); $container = ContainerImpl::getInstance($properties); self::$_logger = \Logger::getLogger(__CLASS__); $baseUrlLen = strlen($baseUrl); ob_start(); $exceptionMapper = $render = $dispatcher = $viewResolver = false; $interceptors = array(); try { $dispatcher = $container->getBean('HttpDispatcher'); $viewResolver = $container->getBean('HttpViewResolver'); $exceptionMapper = $container->getBean('HttpExceptionMapper'); $render = $container->getBean('HttpViewRender'); $method = strtolower($_SERVER['REQUEST_METHOD']); $url = $_SERVER['REQUEST_URI']; $urlStart = strpos($url, $baseUrl); self::$_logger->debug('Trying to match: ' . $url); if ($urlStart === false || $urlStart > 0) { throw new MvcException($url . ' is not a base url.'); } $url = substr($url, $baseUrlLen); $variables = array(); if (!empty($_GET)) { $variables = array_merge($variables, $_GET); } if (!empty($_POST)) { $variables = array_merge($variables, $_POST); } $action = new HttpAction($url, $variables); $action->setMethod($method); $mapper = $container->getBean('HttpUrlMapper'); self::dispatch($dispatcher, $viewResolver, $action, $mapper, $render); } catch (\Exception $exception) { $exceptionThrown = $exception; self::$_logger->debug('Got Exception: ' . $exception); ob_end_clean(); ob_start(); if ($exceptionMapper === false) { header('HTTP/1.1 500 Error.'); } else { $action = new HttpAction(get_class($exception), array('exception' => $exception)); self::dispatch($dispatcher, $viewResolver, $action, $exceptionMapper, $render); } } ob_end_flush(); }
/** * Init session. */ public function init() { $this->httpSession = HttpSession::getSession(); }