41
41
*/
42
42
class SecurityExtension extends Extension implements PrependExtensionInterface
43
43
{
44
- private $ requestMatchers = array () ;
45
- private $ expressions = array () ;
46
- private $ contextListeners = array () ;
47
- private $ listenerPositions = array ( 'pre_auth ' , 'form ' , 'http ' , 'remember_me ' ) ;
48
- private $ factories = array () ;
49
- private $ userProviderFactories = array () ;
50
- private $ statelessFirewallKeys = array () ;
44
+ private $ requestMatchers = [] ;
45
+ private $ expressions = [] ;
46
+ private $ contextListeners = [] ;
47
+ private $ listenerPositions = [ 'pre_auth ' , 'form ' , 'http ' , 'remember_me ' ] ;
48
+ private $ factories = [] ;
49
+ private $ userProviderFactories = [] ;
50
+ private $ statelessFirewallKeys = [] ;
51
51
52
52
public function __construct ()
53
53
{
54
54
foreach ($ this ->listenerPositions as $ position ) {
55
- $ this ->factories [$ position ] = array () ;
55
+ $ this ->factories [$ position ] = [] ;
56
56
}
57
57
}
58
58
@@ -183,7 +183,7 @@ private function createAuthorization($config, ContainerBuilder $container)
183
183
}
184
184
185
185
$ container ->getDefinition ('security.access_map ' )
186
- ->addMethodCall ('add ' , array ( $ matcher , $ attributes , $ access ['requires_channel ' ]) );
186
+ ->addMethodCall ('add ' , [ $ matcher , $ attributes , $ access ['requires_channel ' ]] );
187
187
}
188
188
189
189
// allow cache warm-up for expressions
@@ -207,7 +207,7 @@ private function createFirewalls($config, ContainerBuilder $container)
207
207
// make the ContextListener aware of the configured user providers
208
208
$ contextListenerDefinition = $ container ->getDefinition ('security.context_listener ' );
209
209
$ arguments = $ contextListenerDefinition ->getArguments ();
210
- $ userProviders = array () ;
210
+ $ userProviders = [] ;
211
211
foreach ($ providerIds as $ userProviderId ) {
212
212
$ userProviders [] = new Reference ($ userProviderId );
213
213
}
@@ -222,7 +222,7 @@ private function createFirewalls($config, ContainerBuilder $container)
222
222
223
223
// load firewall map
224
224
$ mapDef = $ container ->getDefinition ('security.firewall.map ' );
225
- $ map = $ authenticationProviders = $ contextRefs = array () ;
225
+ $ map = $ authenticationProviders = $ contextRefs = [] ;
226
226
foreach ($ firewalls as $ name => $ firewall ) {
227
227
if (isset ($ firewall ['user_checker ' ]) && 'security.user_checker ' !== $ firewall ['user_checker ' ]) {
228
228
$ customUserChecker = true ;
@@ -275,7 +275,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
275
275
} elseif (isset ($ firewall ['pattern ' ]) || isset ($ firewall ['host ' ])) {
276
276
$ pattern = isset ($ firewall ['pattern ' ]) ? $ firewall ['pattern ' ] : null ;
277
277
$ host = isset ($ firewall ['host ' ]) ? $ firewall ['host ' ] : null ;
278
- $ methods = isset ($ firewall ['methods ' ]) ? $ firewall ['methods ' ] : array () ;
278
+ $ methods = isset ($ firewall ['methods ' ]) ? $ firewall ['methods ' ] : [] ;
279
279
$ matcher = $ this ->createRequestMatcher ($ container , $ pattern , $ host , null , $ methods );
280
280
}
281
281
@@ -284,7 +284,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
284
284
285
285
// Security disabled?
286
286
if (false === $ firewall ['security ' ]) {
287
- return array ( $ matcher , array () , null , null ) ;
287
+ return [ $ matcher , [] , null , null ] ;
288
288
}
289
289
290
290
$ config ->replaceArgument (4 , $ firewall ['stateless ' ]);
@@ -303,8 +303,8 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
303
303
$ config ->replaceArgument (5 , $ defaultProvider );
304
304
305
305
// Register listeners
306
- $ listeners = array () ;
307
- $ listenerKeys = array () ;
306
+ $ listeners = [] ;
307
+ $ listenerKeys = [] ;
308
308
309
309
// Channel listener
310
310
$ listeners [] = new Reference ('security.channel_listener ' );
@@ -328,11 +328,11 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
328
328
if (isset ($ firewall ['logout ' ])) {
329
329
$ logoutListenerId = 'security.logout_listener. ' .$ id ;
330
330
$ logoutListener = $ container ->setDefinition ($ logoutListenerId , new ChildDefinition ('security.logout_listener ' ));
331
- $ logoutListener ->replaceArgument (3 , array (
331
+ $ logoutListener ->replaceArgument (3 , [
332
332
'csrf_parameter ' => $ firewall ['logout ' ]['csrf_parameter ' ],
333
333
'csrf_token_id ' => $ firewall ['logout ' ]['csrf_token_id ' ],
334
334
'logout_path ' => $ firewall ['logout ' ]['path ' ],
335
- ) );
335
+ ] );
336
336
337
337
// add logout success handler
338
338
if (isset ($ firewall ['logout ' ]['success_handler ' ])) {
@@ -351,7 +351,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
351
351
352
352
// add session logout handler
353
353
if (true === $ firewall ['logout ' ]['invalidate_session ' ] && false === $ firewall ['stateless ' ]) {
354
- $ logoutListener ->addMethodCall ('addHandler ' , array ( new Reference ('security.logout.handler.session ' )) );
354
+ $ logoutListener ->addMethodCall ('addHandler ' , [ new Reference ('security.logout.handler.session ' )] );
355
355
}
356
356
357
357
// add cookie logout handler
@@ -360,25 +360,25 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
360
360
$ cookieHandler = $ container ->setDefinition ($ cookieHandlerId , new ChildDefinition ('security.logout.handler.cookie_clearing ' ));
361
361
$ cookieHandler ->addArgument ($ firewall ['logout ' ]['delete_cookies ' ]);
362
362
363
- $ logoutListener ->addMethodCall ('addHandler ' , array ( new Reference ($ cookieHandlerId )) );
363
+ $ logoutListener ->addMethodCall ('addHandler ' , [ new Reference ($ cookieHandlerId )] );
364
364
}
365
365
366
366
// add custom handlers
367
367
foreach ($ firewall ['logout ' ]['handlers ' ] as $ handlerId ) {
368
- $ logoutListener ->addMethodCall ('addHandler ' , array ( new Reference ($ handlerId )) );
368
+ $ logoutListener ->addMethodCall ('addHandler ' , [ new Reference ($ handlerId )] );
369
369
}
370
370
371
371
// register with LogoutUrlGenerator
372
372
$ container
373
373
->getDefinition ('security.logout_url_generator ' )
374
- ->addMethodCall ('registerListener ' , array (
374
+ ->addMethodCall ('registerListener ' , [
375
375
$ id ,
376
376
$ firewall ['logout ' ]['path ' ],
377
377
$ firewall ['logout ' ]['csrf_token_id ' ],
378
378
$ firewall ['logout ' ]['csrf_parameter ' ],
379
379
isset ($ firewall ['logout ' ]['csrf_token_generator ' ]) ? new Reference ($ firewall ['logout ' ]['csrf_token_generator ' ]) : null ,
380
380
false === $ firewall ['stateless ' ] && isset ($ firewall ['context ' ]) ? $ firewall ['context ' ] : null ,
381
- ) )
381
+ ] )
382
382
;
383
383
}
384
384
@@ -425,7 +425,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
425
425
$ config ->replaceArgument (10 , $ listenerKeys );
426
426
$ config ->replaceArgument (11 , isset ($ firewall ['switch_user ' ]) ? $ firewall ['switch_user ' ] : null );
427
427
428
- return array ( $ matcher , $ listeners , $ exceptionListener , null !== $ logoutListenerId ? new Reference ($ logoutListenerId ) : null ) ;
428
+ return [ $ matcher , $ listeners , $ exceptionListener , null !== $ logoutListenerId ? new Reference ($ logoutListenerId ) : null ] ;
429
429
}
430
430
431
431
private function createContextListener ($ container , $ contextKey )
@@ -443,7 +443,7 @@ private function createContextListener($container, $contextKey)
443
443
444
444
private function createAuthenticationListeners ($ container , $ id , $ firewall , &$ authenticationProviders , $ defaultProvider = null , array $ providerIds , $ defaultEntryPoint )
445
445
{
446
- $ listeners = array () ;
446
+ $ listeners = [] ;
447
447
$ hasListeners = false ;
448
448
449
449
foreach ($ this ->listenerPositions as $ position ) {
@@ -505,19 +505,19 @@ private function createAuthenticationListeners($container, $id, $firewall, &$aut
505
505
throw new InvalidConfigurationException (sprintf ('No authentication listener registered for firewall "%s". ' , $ id ));
506
506
}
507
507
508
- return array ( $ listeners , $ defaultEntryPoint) ;
508
+ return [ $ listeners , $ defaultEntryPoint] ;
509
509
}
510
510
511
511
private function createEncoders ($ encoders , ContainerBuilder $ container )
512
512
{
513
- $ encoderMap = array () ;
513
+ $ encoderMap = [] ;
514
514
foreach ($ encoders as $ class => $ encoder ) {
515
515
$ encoderMap [$ class ] = $ this ->createEncoder ($ encoder , $ container );
516
516
}
517
517
518
518
$ container
519
519
->getDefinition ('security.encoder_factory.generic ' )
520
- ->setArguments (array ( $ encoderMap) )
520
+ ->setArguments ([ $ encoderMap] )
521
521
;
522
522
}
523
523
@@ -530,33 +530,33 @@ private function createEncoder($config, ContainerBuilder $container)
530
530
531
531
// plaintext encoder
532
532
if ('plaintext ' === $ config ['algorithm ' ]) {
533
- $ arguments = array ( $ config ['ignore_case ' ]) ;
533
+ $ arguments = [ $ config ['ignore_case ' ]] ;
534
534
535
- return array (
535
+ return [
536
536
'class ' => 'Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder ' ,
537
537
'arguments ' => $ arguments ,
538
- ) ;
538
+ ] ;
539
539
}
540
540
541
541
// pbkdf2 encoder
542
542
if ('pbkdf2 ' === $ config ['algorithm ' ]) {
543
- return array (
543
+ return [
544
544
'class ' => 'Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder ' ,
545
- 'arguments ' => array (
545
+ 'arguments ' => [
546
546
$ config ['hash_algorithm ' ],
547
547
$ config ['encode_as_base64 ' ],
548
548
$ config ['iterations ' ],
549
549
$ config ['key_length ' ],
550
- ) ,
551
- ) ;
550
+ ] ,
551
+ ] ;
552
552
}
553
553
554
554
// bcrypt encoder
555
555
if ('bcrypt ' === $ config ['algorithm ' ]) {
556
- return array (
556
+ return [
557
557
'class ' => 'Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder ' ,
558
- 'arguments ' => array ( $ config ['cost ' ]) ,
559
- ) ;
558
+ 'arguments ' => [ $ config ['cost ' ]] ,
559
+ ] ;
560
560
}
561
561
562
562
// Argon2i encoder
@@ -569,14 +569,14 @@ private function createEncoder($config, ContainerBuilder $container)
569
569
throw new InvalidConfigurationException ('Argon2i algorithm is not supported. Install the libsodium extension or use BCrypt instead. ' );
570
570
}
571
571
572
- return array (
572
+ return [
573
573
'class ' => 'Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder ' ,
574
- 'arguments ' => array (
574
+ 'arguments ' => [
575
575
$ config ['memory_cost ' ],
576
576
$ config ['time_cost ' ],
577
577
$ config ['threads ' ],
578
- ) ,
579
- ) ;
578
+ ] ,
579
+ ] ;
580
580
}
581
581
582
582
// run-time configured encoder
@@ -586,7 +586,7 @@ private function createEncoder($config, ContainerBuilder $container)
586
586
// Parses user providers and returns an array of their ids
587
587
private function createUserProviders ($ config , ContainerBuilder $ container )
588
588
{
589
- $ providerIds = array () ;
589
+ $ providerIds = [] ;
590
590
foreach ($ config ['providers ' ] as $ name => $ provider ) {
591
591
$ id = $ this ->createUserDaoProvider ($ name , $ provider , $ container );
592
592
$ providerIds [str_replace ('- ' , '_ ' , $ name )] = $ id ;
@@ -620,7 +620,7 @@ private function createUserDaoProvider($name, $provider, ContainerBuilder $conta
620
620
621
621
// Chain provider
622
622
if (isset ($ provider ['chain ' ])) {
623
- $ providers = array () ;
623
+ $ providers = [] ;
624
624
foreach ($ provider ['chain ' ]['providers ' ] as $ providerName ) {
625
625
$ providers [] = new Reference ($ this ->getUserProviderId ($ providerName ));
626
626
}
@@ -697,20 +697,20 @@ private function createExpression($container, $expression)
697
697
return $ this ->expressions [$ id ] = new Reference ($ id );
698
698
}
699
699
700
- private function createRequestMatcher ($ container , $ path = null , $ host = null , int $ port = null , $ methods = array () , $ ip = null , array $ attributes = array () )
700
+ private function createRequestMatcher ($ container , $ path = null , $ host = null , int $ port = null , $ methods = [] , $ ip = null , array $ attributes = [] )
701
701
{
702
702
if ($ methods ) {
703
703
$ methods = array_map ('strtoupper ' , (array ) $ methods );
704
704
}
705
705
706
- $ id = '.security.request_matcher. ' .ContainerBuilder::hash (array ( $ path , $ host , $ port , $ methods , $ ip , $ attributes) );
706
+ $ id = '.security.request_matcher. ' .ContainerBuilder::hash ([ $ path , $ host , $ port , $ methods , $ ip , $ attributes] );
707
707
708
708
if (isset ($ this ->requestMatchers [$ id ])) {
709
709
return $ this ->requestMatchers [$ id ];
710
710
}
711
711
712
712
// only add arguments that are necessary
713
- $ arguments = array ( $ path , $ host , $ methods , $ ip , $ attributes , null , $ port) ;
713
+ $ arguments = [ $ path , $ host , $ methods , $ ip , $ attributes , null , $ port] ;
714
714
while (\count ($ arguments ) > 0 && !end ($ arguments )) {
715
715
array_pop ($ arguments );
716
716
}
0 commit comments