Skip to content

Commit

Permalink
fix interface
Browse files Browse the repository at this point in the history
  • Loading branch information
phiamo committed Nov 3, 2024
1 parent 949045d commit 29c71f1
Showing 1 changed file with 170 additions and 162 deletions.
332 changes: 170 additions & 162 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of the LuneticsLocaleBundle package.
*
Expand All @@ -7,6 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that is distributed with this source code.
*/

namespace Lunetics\LocaleBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -22,7 +24,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('lunetics_locale');

Expand All @@ -37,167 +39,173 @@ public function getConfigTreeBuilder()
$rootNode
->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;
Expand Down

0 comments on commit 29c71f1

Please sign in to comment.