From 3a526fe025cd20e04a6a11370cf5ab28dbb5a544 Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Mon, 24 Jun 2024 23:25:28 +0200 Subject: [PATCH] Fixed default boolean values being overwritten in per-path configs (#186) --- DependencyInjection/Configuration.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e4f4d1b..900fb12 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -40,7 +40,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->children() ->arrayNode('defaults') ->addDefaultsIfNotSet() - ->append($this->getAllowCredentials()) + ->append($this->getAllowCredentials(true)) ->append($this->getAllowOrigin()) ->append($this->getAllowHeaders()) ->append($this->getAllowMethods()) @@ -48,9 +48,9 @@ public function getConfigTreeBuilder(): TreeBuilder ->append($this->getExposeHeaders()) ->append($this->getMaxAge()) ->append($this->getHosts()) - ->append($this->getOriginRegex()) + ->append($this->getOriginRegex(true)) ->append($this->getForcedAllowOriginValue()) - ->append($this->getSkipSameAsOrigin()) + ->append($this->getSkipSameAsOrigin(true)) ->end() ->arrayNode('paths') @@ -75,18 +75,24 @@ public function getConfigTreeBuilder(): TreeBuilder return $treeBuilder; } - private function getSkipSameAsOrigin(): BooleanNodeDefinition + private function getSkipSameAsOrigin(bool $withDefaultValue = false): BooleanNodeDefinition { $node = new BooleanNodeDefinition('skip_same_as_origin'); - $node->defaultTrue(); + + if ($withDefaultValue) { + $node->defaultTrue(); + } return $node; } - private function getAllowCredentials(): BooleanNodeDefinition + private function getAllowCredentials(bool $withDefaultValue = false): BooleanNodeDefinition { $node = new BooleanNodeDefinition('allow_credentials'); - $node->defaultFalse(); + + if ($withDefaultValue) { + $node->defaultFalse(); + } return $node; } @@ -192,10 +198,13 @@ private function getHosts(): ArrayNodeDefinition return $node; } - private function getOriginRegex(): BooleanNodeDefinition + private function getOriginRegex(bool $withDefaultValue = false): BooleanNodeDefinition { $node = new BooleanNodeDefinition('origin_regex'); - $node->defaultFalse(); + + if ($withDefaultValue) { + $node->defaultFalse(); + } return $node; }