class LocaleListener

Initializes the locale based on the current request.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of LocaleListener

1 file declares its use of LocaleListener
LocaleListenerTest.php in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/LocaleListener.php, line 24

Namespace

Symfony\Component\HttpKernel\EventListener
View source
class LocaleListener implements EventSubscriberInterface {
  private $router;
  private $defaultLocale;
  public function __construct($defaultLocale = 'en', RequestContextAwareInterface $router = null) {
    $this->defaultLocale = $defaultLocale;
    $this->router = $router;
  }
  public function onKernelRequest(GetResponseEvent $event) {
    $request = $event
      ->getRequest();
    $request
      ->setDefaultLocale($this->defaultLocale);
    if ($locale = $request->attributes
      ->get('_locale')) {
      $request
        ->setLocale($locale);
    }
    if (null !== $this->router) {
      $this->router
        ->getContext()
        ->setParameter('_locale', $request
        ->getLocale());
    }
  }
  public static function getSubscribedEvents() {
    return array(
      // must be registered after the Router to have access to the _locale
      KernelEvents::REQUEST => array(
        array(
          'onKernelRequest',
          16,
        ),
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LocaleListener::$defaultLocale private property
LocaleListener::$router private property
LocaleListener::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents
LocaleListener::onKernelRequest public function
LocaleListener::__construct public function