public function testRequestLocaleIsNotOverridden()
 {
     $request = Request::create('/');
     $request->setLocale('de');
     $listener = new LocaleListener('fr', null, $this->requestStack);
     $event = $this->getEvent($request);
     $listener->onKernelRequest($event);
     $this->assertEquals('de', $request->getLocale());
 }
Example #2
0
 public function testLocaleSetForRoutingContext()
 {
     // the request context is updated
     $context = $this->getMock('Symfony\\Component\\Routing\\RequestContext');
     $context->expects($this->once())->method('setParameter')->with('_locale', 'es');
     $router = $this->getMock('Symfony\\Component\\Routing\\Router', array('getContext'), array(), '', false);
     $router->expects($this->once())->method('getContext')->will($this->returnValue($context));
     $request = Request::create('/');
     $request->attributes->set('_locale', 'es');
     $listener = new LocaleListener('fr', $router);
     $listener->onKernelRequest($this->getEvent($request));
 }
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->has('_locale')) {
         foreach ($this->configResolver->getParameter('languages') as $locale) {
             $convertedLocale = $this->localeConverter->convertToPOSIX($locale);
             if ($convertedLocale !== null) {
                 // Setting the converted locale to the _locale request attribute, so that it can be properly processed by parent listener.
                 $request->attributes->set('_locale', $convertedLocale);
                 break;
             }
         }
     }
     parent::onKernelRequest($event);
 }
 public function onKernelRequest(GetResponseEvent $event)
 {
     parent::onKernelRequest($event);
     $this->app['locale'] = $event->getRequest()->getLocale();
 }
 /**
  * Gets a listener priority max.
  *
  * The priority max is a LocaleListener priority.
  *
  * @return int
  */
 public static function getPriorityMax()
 {
     $events = LocaleListener::getSubscribedEvents();
     return $events[KernelEvents::REQUEST][0][1];
 }