diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 1efb9ed..928b51d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -1,4 +1,5 @@ fixXmlConfig('allowed_locale') ->children() - ->scalarNode('strict_mode') - ->defaultFalse() - ->end() - ->scalarNode('strict_match') - ->defaultFalse() - ->end() - ->booleanNode('disable_vary_header')->defaultFalse()->end() - ->arrayNode('allowed_locales') - ->requiresAtLeastOneElement() - ->prototype('scalar')->end() - ->end() - ->scalarNode('guessing_excluded_pattern') - ->defaultNull() - ->end() - ->arrayNode('guessing_order') - ->beforeNormalization() - ->ifString() - ->then(function ($v) { return array($v); }) - ->end() - ->isRequired() - ->requiresAtLeastOneElement() - ->prototype('scalar')->end() - ->end() - ->arrayNode('router_guesser') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('class') - ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\RouterLocaleGuesser') - ->end() - ->end() - ->end() - ->arrayNode('browser_guesser') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('class') - ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\BrowserLocaleGuesser') - ->end() - ->end() - ->end() - ->arrayNode('cookie_guesser') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('class') - ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\CookieLocaleGuesser') - ->end() - ->end() - ->end() - ->arrayNode('session_guesser') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('class') - ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\SessionLocaleGuesser') - ->end() - ->end() - ->end() - ->arrayNode('query_guesser') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('class') - ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\QueryLocaleGuesser') - ->end() - ->end() - ->end() - ->arrayNode('subdomain_guesser') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('class') - ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\SubdomainLocaleGuesser') - ->end() - ->end() - ->end() - ->arrayNode('topleveldomain_guesser') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('class') - ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\TopleveldomainLocaleGuesser') - ->end() - ->end() - ->end() - ->arrayNode('domain_guesser') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('class') - ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\DomainLocaleGuesser') - ->end() - ->end() - ->end() - ->arrayNode('cookie') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('set_on_change')->defaultTrue()->end() - ->scalarNode('class')->defaultValue('Lunetics\LocaleBundle\Cookie\LocaleCookie')->end() - ->scalarNode('name')->defaultValue('lunetics_locale')->end() - ->scalarNode('ttl')->defaultValue('86400')->end() - ->scalarNode('path')->defaultValue('/')->end() - ->scalarNode('domain')->defaultValue(null)->end() - ->scalarNode('secure')->defaultFalse()->end() - ->scalarNode('httpOnly')->defaultTrue()->end() - ->end() - ->end() - ->arrayNode('session') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('variable')->defaultValue('lunetics_locale')->end() - ->end() - ->end() - ->arrayNode('query') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('parameter_name')->defaultValue('_locale')->end() - ->end() - ->end() - ->arrayNode('subdomain') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('region_separator')->defaultValue('_')->end() - ->end() - ->end() - ->arrayNode('topleveldomain') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('locale_map') - ->useAttributeAsKey('name') - ->prototype('scalar')->end() - ->end() - ->end() - ->end() - ->arrayNode('domain') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('locale_map') - ->normalizeKeys(false) - ->useAttributeAsKey('name') - ->prototype('scalar')->end() - ->end() - ->end() - ->end() - ->arrayNode('form') - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('languages_only')->defaultTrue()->end() - ->booleanNode('strict_mode')->defaultFalse()->end() - ->end() - ->end() - ->arrayNode('switcher') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('template')->defaultValue('links')->end() - ->booleanNode('show_current_locale')->defaultFalse()->end() - ->scalarNode('redirect_to_route')->defaultNull()->end() - ->scalarNode('redirect_statuscode')->defaultValue('302')->end() - ->booleanNode('use_controller')->defaultFalse()->end() - ->booleanNode('use_referrer')->defaultTrue()->end() - ->end() - ->validate() - ->ifTrue(function($v) { return is_null($v['redirect_to_route']);}) - ->thenInvalid('You need to specify a default fallback route for the use_controller configuration') - ->ifTrue(function($v) use ($validStatuscodes) { return !in_array(intval($v['redirect_statuscode']), $validStatuscodes);}) - ->thenInvalid(sprintf("Invalid HTTP statuscode. Available statuscodes for redirection are:\n\n%s \n\nSee reference for HTTP status codes", implode(", ",$validStatuscodes))) - ->end() - ->end() + ->scalarNode('strict_mode') + ->defaultFalse() + ->end() + ->scalarNode('strict_match') + ->defaultFalse() + ->end() + ->booleanNode('disable_vary_header')->defaultFalse()->end() + ->arrayNode('allowed_locales') + ->requiresAtLeastOneElement() + ->prototype('scalar')->end() + ->end() + ->scalarNode('guessing_excluded_pattern') + ->defaultNull() + ->end() + ->arrayNode('guessing_order') + ->beforeNormalization() + ->ifString() + ->then(function ($v) { + return array($v); + }) + ->end() + ->isRequired() + ->requiresAtLeastOneElement() + ->prototype('scalar')->end() + ->end() + ->arrayNode('router_guesser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class') + ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\RouterLocaleGuesser') + ->end() + ->end() + ->end() + ->arrayNode('browser_guesser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class') + ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\BrowserLocaleGuesser') + ->end() + ->end() + ->end() + ->arrayNode('cookie_guesser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class') + ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\CookieLocaleGuesser') + ->end() + ->end() + ->end() + ->arrayNode('session_guesser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class') + ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\SessionLocaleGuesser') + ->end() + ->end() + ->end() + ->arrayNode('query_guesser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class') + ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\QueryLocaleGuesser') + ->end() + ->end() + ->end() + ->arrayNode('subdomain_guesser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class') + ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\SubdomainLocaleGuesser') + ->end() + ->end() + ->end() + ->arrayNode('topleveldomain_guesser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class') + ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\TopleveldomainLocaleGuesser') + ->end() + ->end() + ->end() + ->arrayNode('domain_guesser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class') + ->defaultValue('Lunetics\LocaleBundle\LocaleGuesser\DomainLocaleGuesser') + ->end() + ->end() + ->end() + ->arrayNode('cookie') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('set_on_change')->defaultTrue()->end() + ->scalarNode('class')->defaultValue('Lunetics\LocaleBundle\Cookie\LocaleCookie')->end() + ->scalarNode('name')->defaultValue('lunetics_locale')->end() + ->scalarNode('ttl')->defaultValue('86400')->end() + ->scalarNode('path')->defaultValue('/')->end() + ->scalarNode('domain')->defaultValue(null)->end() + ->scalarNode('secure')->defaultFalse()->end() + ->scalarNode('httpOnly')->defaultTrue()->end() + ->end() + ->end() + ->arrayNode('session') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('variable')->defaultValue('lunetics_locale')->end() + ->end() + ->end() + ->arrayNode('query') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('parameter_name')->defaultValue('_locale')->end() + ->end() + ->end() + ->arrayNode('subdomain') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('region_separator')->defaultValue('_')->end() + ->end() + ->end() + ->arrayNode('topleveldomain') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('locale_map') + ->useAttributeAsKey('name') + ->prototype('scalar')->end() + ->end() + ->end() + ->end() + ->arrayNode('domain') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('locale_map') + ->normalizeKeys(false) + ->useAttributeAsKey('name') + ->prototype('scalar')->end() + ->end() + ->end() + ->end() + ->arrayNode('form') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('languages_only')->defaultTrue()->end() + ->booleanNode('strict_mode')->defaultFalse()->end() + ->end() + ->end() + ->arrayNode('switcher') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('template')->defaultValue('links')->end() + ->booleanNode('show_current_locale')->defaultFalse()->end() + ->scalarNode('redirect_to_route')->defaultNull()->end() + ->scalarNode('redirect_statuscode')->defaultValue('302')->end() + ->booleanNode('use_controller')->defaultFalse()->end() + ->booleanNode('use_referrer')->defaultTrue()->end() + ->end() + ->validate() + ->ifTrue(function ($v) { + return is_null($v['redirect_to_route']); + }) + ->thenInvalid('You need to specify a default fallback route for the use_controller configuration') + ->ifTrue(function ($v) use ($validStatuscodes) { + return !in_array(intval($v['redirect_statuscode']), $validStatuscodes); + }) + ->thenInvalid(sprintf("Invalid HTTP statuscode. Available statuscodes for redirection are:\n\n%s \n\nSee reference for HTTP status codes", implode(", ", $validStatuscodes))) + ->end() + ->end() ->end(); return $treeBuilder;