diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index cc4a9da..cc8a779 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -114,6 +114,7 @@ public function getConfigTreeBuilder() ->booleanNode('httponly')->defaultFalse()->end() ->end() ->end() + ->booleanNode('accept_header_languages')->defaultTrue()->end() ->end() ->end() ; diff --git a/DependencyInjection/JMSI18nRoutingExtension.php b/DependencyInjection/JMSI18nRoutingExtension.php index 9bc1549..b38ed01 100644 --- a/DependencyInjection/JMSI18nRoutingExtension.php +++ b/DependencyInjection/JMSI18nRoutingExtension.php @@ -45,6 +45,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('jms_i18n_routing.strategy', $config['strategy']); $container->setParameter('jms_i18n_routing.redirect_to_host', $config['redirect_to_host']); $container->setParameter('jms_i18n_routing.cookie.name', $config['cookie']['name']); + $container->setParameter('jms_i18n_routing.accept_header_languages', $config['accept_header_languages']); $this->addClassesToCompile(array( $container->getDefinition('jms_i18n_routing.router')->getClass(), diff --git a/Resources/config/services.xml b/Resources/config/services.xml index a5c3f66..74b4a75 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -21,6 +21,7 @@ %jms_i18n_routing.cookie.name% + %jms_i18n_routing.accept_header_languages% diff --git a/Router/DefaultLocaleResolver.php b/Router/DefaultLocaleResolver.php index 9bb5406..28058b4 100755 --- a/Router/DefaultLocaleResolver.php +++ b/Router/DefaultLocaleResolver.php @@ -22,10 +22,11 @@ class DefaultLocaleResolver implements LocaleResolverInterface private $cookieName; private $hostMap; - public function __construct($cookieName, array $hostMap = array()) + public function __construct($cookieName, $acceptHeaderLanguages = true, array $hostMap = array()) { $this->cookieName = $cookieName; $this->hostMap = $hostMap; + $this->acceptHeaderLanguages = $acceptHeaderLanguages; } /** @@ -64,7 +65,7 @@ public function resolveLocale(Request $request, array $availableLocales) } // use accept header for locale matching if sent - if ($languages = $request->getLanguages()) { + if (true == $this->acceptHeaderLanguages && $languages = $request->getLanguages()) { foreach ($languages as $lang) { if (in_array($lang, $availableLocales, true)) { return $lang; @@ -74,4 +75,4 @@ public function resolveLocale(Request $request, array $availableLocales) return null; } -} \ No newline at end of file +}