@@ -57,8 +57,8 @@ public function getConfigTreeBuilder(): TreeBuilder
5757 $ rootNode
5858 ->docUrl ('https://symfony.com/doc/{version:major}.{version:minor}/reference/configuration/security.html ' , 'symfony/security-bundle ' )
5959 ->beforeNormalization ()
60- ->always ()
61- ->then (function ($ v ) {
60+ ->ifArray ()
61+ ->then (static function ($ v ) {
6262 if (isset ($ v ['hide_user_not_found ' ]) && isset ($ v ['expose_security_errors ' ])) {
6363 throw new InvalidConfigurationException ('You cannot use both "hide_user_not_found" and "expose_security_errors" at the same time. ' );
6464 }
@@ -80,7 +80,7 @@ public function getConfigTreeBuilder(): TreeBuilder
8080 ->setDeprecated ('symfony/security-bundle ' , '7.3 ' , 'The "%node%" option is deprecated and will be removed in 8.0. Use the "expose_security_errors" option instead. ' )
8181 ->end ()
8282 ->enumNode ('expose_security_errors ' )
83- ->beforeNormalization ()->ifString ()->then (fn ($ v ) => ExposeSecurityLevel::tryFrom ($ v ))->end ()
83+ ->beforeNormalization ()->ifString ()->then (static fn ($ v ) => ExposeSecurityLevel::tryFrom ($ v ))->end ()
8484 ->values (ExposeSecurityLevel::cases ())
8585 ->defaultValue (ExposeSecurityLevel::None)
8686 ->end ()
@@ -129,11 +129,7 @@ private function addRoleHierarchySection(ArrayNodeDefinition $rootNode): void
129129 ->useAttributeAsKey ('id ' )
130130 ->prototype ('array ' )
131131 ->performNoDeepMerging ()
132- ->beforeNormalization ()->ifString ()->then (fn ($ v ) => ['value ' => $ v ])->end ()
133- ->beforeNormalization ()
134- ->ifTrue (fn ($ v ) => \is_array ($ v ) && isset ($ v ['value ' ]))
135- ->then (fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ['value ' ]))
136- ->end ()
132+ ->beforeNormalization ()->ifString ()->then (static fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))->end ()
137133 ->prototype ('scalar ' )->end ()
138134 ->end ()
139135 ->end ()
@@ -159,7 +155,7 @@ private function addAccessControlSection(ArrayNodeDefinition $rootNode): void
159155 ->scalarNode ('host ' )->defaultNull ()->end ()
160156 ->integerNode ('port ' )->defaultNull ()->end ()
161157 ->arrayNode ('ips ' , 'ip ' )
162- ->beforeNormalization ()-> ifString ()-> then ( fn ( $ v ) => [ $ v ])-> end ( )
158+ ->acceptAndWrap ([ ' string ' ] )
163159 ->prototype ('scalar ' )->end ()
164160 ->end ()
165161 ->arrayNode ('attributes ' , 'attribute ' )
@@ -168,14 +164,14 @@ private function addAccessControlSection(ArrayNodeDefinition $rootNode): void
168164 ->end ()
169165 ->scalarNode ('route ' )->defaultNull ()->end ()
170166 ->arrayNode ('methods ' , 'method ' )
171- ->beforeNormalization ()->ifString ()->then (fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))->end ()
167+ ->beforeNormalization ()->ifString ()->then (static fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))->end ()
172168 ->prototype ('scalar ' )->end ()
173169 ->end ()
174170 ->scalarNode ('allow_if ' )->defaultNull ()->end ()
175171 ->end ()
176172 ->children ()
177173 ->arrayNode ('roles ' , 'role ' )
178- ->beforeNormalization ()->ifString ()->then (fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))->end ()
174+ ->beforeNormalization ()->ifString ()->then (static fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))->end ()
179175 ->prototype ('scalar ' )->end ()
180176 ->end ()
181177 ->end ()
@@ -205,12 +201,12 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
205201 ->scalarNode ('pattern ' )
206202 ->beforeNormalization ()
207203 ->ifArray ()
208- ->then (fn ($ v ) => \sprintf ('(?:%s) ' , implode ('| ' , $ v )))
204+ ->then (static fn ($ v ) => \sprintf ('(?:%s) ' , implode ('| ' , $ v )))
209205 ->end ()
210206 ->end ()
211207 ->scalarNode ('host ' )->end ()
212208 ->arrayNode ('methods ' )
213- ->beforeNormalization ()->ifString ()->then (fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))->end ()
209+ ->beforeNormalization ()->ifString ()->then (static fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))->end ()
214210 ->prototype ('scalar ' )->end ()
215211 ->end ()
216212 ->booleanNode ('security ' )->defaultTrue ()->end ()
@@ -233,11 +229,11 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
233229 ->treatTrueLike ([])
234230 ->canBeUnset ()
235231 ->beforeNormalization ()
236- ->ifTrue ( fn ( $ v ): bool => \is_array ( $ v ) && ( isset ( $ v [ ' csrf_token_manager ' ]) xor isset ( $ v [ ' enable_csrf ' ])) )
237- ->then (function (array $ v ): array {
232+ ->ifArray ( )
233+ ->then (static function ($ v ) {
238234 if (isset ($ v ['csrf_token_manager ' ])) {
239- $ v ['enable_csrf ' ] = true ;
240- } elseif ($ v ['enable_csrf ' ]) {
235+ $ v ['enable_csrf ' ] ?? = true ;
236+ } elseif ($ v ['enable_csrf ' ] ?? false ) {
241237 $ v ['csrf_token_manager ' ] = 'security.csrf.token_manager ' ;
242238 }
243239
@@ -254,7 +250,7 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
254250 ->booleanNode ('invalidate_session ' )->defaultTrue ()->end ()
255251 ->arrayNode ('clear_site_data ' )
256252 ->performNoDeepMerging ()
257- ->beforeNormalization ()->ifString ()->then (fn ($ v ) => $ v ? array_map ('trim ' , explode (', ' , $ v )) : [])->end ()
253+ ->beforeNormalization ()->ifString ()->then (static fn ($ v ) => $ v ? array_map ('trim ' , explode (', ' , $ v )) : [])->end ()
258254 ->enumPrototype ()
259255 ->values ([
260256 '* ' , 'cache ' , 'cookies ' , 'storage ' , 'executionContexts ' ,
@@ -265,9 +261,10 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
265261 ->children ()
266262 ->arrayNode ('delete_cookies ' , 'delete_cookie ' )
267263 ->normalizeKeys (false )
264+ ->acceptAndWrap (['string ' ])
268265 ->beforeNormalization ()
269- ->ifTrue ( fn ( $ v ) => \is_array ( $ v ) && \is_int ( key ( $ v )) )
270- ->then (fn ($ v ) => array_map (fn ($ v ) => ['name ' => $ v ], $ v ))
266+ ->ifArray ( )
267+ ->then (static fn ($ v ) => array_map (static fn ($ v ) => \is_string ( $ v ) ? ['name ' => $ v ] : $ v , $ v ))
271268 ->end ()
272269 ->useAttributeAsKey ('name ' )
273270 ->prototype ('array ' )
@@ -379,10 +376,7 @@ private function addProvidersSection(ArrayNodeDefinition $rootNode): void
379376 ->arrayNode ('chain ' )
380377 ->children ()
381378 ->arrayNode ('providers ' , 'provider ' )
382- ->beforeNormalization ()
383- ->ifString ()
384- ->then (fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))
385- ->end ()
379+ ->beforeNormalization ()->ifString ()->then (static fn ($ v ) => preg_split ('/\s*,\s*/ ' , $ v ))->end ()
386380 ->prototype ('scalar ' )->end ()
387381 ->end ()
388382 ->end ()
@@ -427,7 +421,7 @@ private function addPasswordHashersSection(ArrayNodeDefinition $rootNode): void
427421 ->prototype ('array ' )
428422 ->canBeUnset ()
429423 ->performNoDeepMerging ()
430- ->beforeNormalization ()-> ifString ()-> then ( fn ( $ v ) => [ ' algorithm ' => $ v ])-> end ( )
424+ ->acceptAndWrap ([ ' string ' ], ' algorithm ' )
431425 ->children ()
432426 ->scalarNode ('algorithm ' )
433427 ->cannotBeEmpty ()
@@ -437,8 +431,8 @@ private function addPasswordHashersSection(ArrayNodeDefinition $rootNode): void
437431 ->end ()
438432 ->end ()
439433 ->arrayNode ('migrate_from ' )
434+ ->acceptAndWrap (['string ' ])
440435 ->prototype ('scalar ' )->end ()
441- ->beforeNormalization ()->castToArray ()->end ()
442436 ->end ()
443437 ->scalarNode ('hash_algorithm ' )->info ('Name of hashing algorithm for PBKDF2 (i.e. sha256, sha512, etc..) See hash_algos() for a list of supported algorithms. ' )->defaultValue ('sha512 ' )->end ()
444438 ->scalarNode ('key_length ' )->defaultValue (40 )->end ()
0 commit comments