Permalink
Browse files

Updated to not use the controller as default!

Added some validation for the config file.
  • Loading branch information...
lunetics committed Oct 25, 2012
1 parent 8288b2a commit 9f4a2de36a53d2111abf63071b83c5dc9fec71fe
@@ -27,6 +27,8 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('lunetics_locale');
+ $validStatuscodes = array(300, 301, 302, 303, 307);
+
$rootNode
->children()
->scalarNode('strict_mode')
@@ -111,17 +113,19 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->scalarNode('template')->defaultValue('links')->end()
- ->scalarNode('show_current_locale')->defaultFalse()->end()
+ ->booleanNode('show_current_locale')->defaultFalse()->end()
->scalarNode('redirect_to_route')->defaultNull()->end()
->scalarNode('redirect_statuscode')->defaultValue('302')->end()
- ->scalarNode('use_controller')->defaultTrue()
- ->validate()
- ->ifNull(function($v) {return $v['switcher']['redirect_to_route'];})
- ->thenInvalid('You need to specify a default fallback route for the use_controller configuration')
- ->end()
- ->end()
- ->scalarNode('use_referrer')->defaultTrue()->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;
@@ -35,7 +35,7 @@ class TargetInformationBuilder
* @param bool $showCurrentLocale Config Var
* @param bool $useController Config Var
*/
- public function __construct(Request $request, RouterInterface $router, $allowedLocales = array(), $showCurrentLocale = false, $useController = true)
+ public function __construct(Request $request, RouterInterface $router, $allowedLocales = array(), $showCurrentLocale = false, $useController = false)
{
$this->request = $request;
$this->router = $router;
@@ -74,7 +74,7 @@ public function testNotProvideRouteInInformationBuilder($route, $locale, $allowe
->method('generate');
}
- $targetInformationBuilder = new TargetInformationBuilder($request, $router, $allowedLocales);
+ $targetInformationBuilder = new TargetInformationBuilder($request, $router, $allowedLocales, false, true);
$targetInformation = $targetInformationBuilder->getTargetInformations();
$this->assertEquals($route, $targetInformation['current_route']);

0 comments on commit 9f4a2de

Please sign in to comment.