/**
  * parse Accept-Language header from request.
  *
  * @param GetResponseEvent $event listener event
  *
  * @return void
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $headers = AcceptHeader::fromString($request->headers->get('Accept-Language'));
     $languages = array_intersect(array_map(function ($header) {
         return $header->getValue();
     }, $headers->all()), array_map(function ($language) {
         return $language->getId();
     }, $this->repository->findAll()));
     if (empty($languages)) {
         $languages[$this->defaultLocale] = $this->defaultLocale;
     }
     $request->attributes->set('languages', $languages);
 }
Exemple #2
0
 /**
  * Returns all languages as a simple flat array
  *
  * @return array array of language id's
  */
 public function getLanguages()
 {
     $languages = array();
     foreach ($this->languageRepository->findAll() as $lang) {
         $languages[] = $lang->getId();
     }
     return $languages;
 }