3 namespace Rapsys\BlogBundle\Controller
; 
   5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
; 
   7 class DefaultController 
extends Controller 
{ 
   9          * Redirect on first supported language version 
  11         public function rootAction() { 
  15                 //Supported application languages 
  16                 $supportedLanguage = explode('|', $this->getParameter('blog.locales')); 
  19                 if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { 
  21                         $httpAcceptLanguage = []; 
  24                         foreach(explode(',',str_replace('-','_',$_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $candidate) { 
  25                                 //Extract candidate and optional weight 
  26                                 @list($candidate, $weight) = explode(';', $candidate); 
  27                                 if (!empty($candidate)) { 
  28                                         $httpAcceptLanguage[!empty($weight)?$weight:1][] = $candidate; 
  33                         if (!empty($httpAcceptLanguage)) { 
  34                                 foreach($httpAcceptLanguage as $weight => $candidates) { 
  35                                         if (($candidate = array_intersect($candidates, $supportedLanguage)) && ($candidate = reset($candidate))) { 
  43                 //Redirect to localised homepage 
  44                 return $this->redirectToRoute('homepage', array('_locale' => $locale), 302);