1515
1616use Symfony \Bundle \SecurityBundle \DependencyInjection \Security \Factory \SecurityFactoryInterface ;
1717use Symfony \Component \Config \Definition \Builder \NodeDefinition ;
18- use Symfony \Component \DependencyInjection \ChildDefinition ;
1918use Symfony \Component \DependencyInjection \ContainerBuilder ;
20- use Symfony \Component \DependencyInjection \DefinitionDecorator ;
2119use Symfony \Component \DependencyInjection \Reference ;
2220
2321/**
@@ -32,24 +30,21 @@ class OAuthFactory implements SecurityFactoryInterface
3230 */
3331 public function create (ContainerBuilder $ container , $ id , $ config , $ userProvider , $ defaultEntryPoint )
3432 {
35- $ providerId = 'security.authentication.provider.fos_oauth_server. ' .$ id ;
36- if (class_exists (ChildDefinition::class)) {
37- $ definition = new ChildDefinition ('fos_oauth_server.security.authentication.provider ' );
38- } else {
39- $ definition = new DefinitionDecorator ('fos_oauth_server.security.authentication.provider ' );
33+ // NOTE: done like this to avoid PHPStan complaining about a missing class for both Symfony v3 and Symfony v4
34+ $ definitionDecorator = 'Symfony \\Component \\DependencyInjection \\DefinitionDecorator ' ;
35+ $ childDefinition = 'Symfony \\Component \\DependencyInjection \\ChildDefinition ' ;
36+ $ definitionClass = $ childDefinition ;
37+ if (class_exists ($ definitionDecorator )) {
38+ $ definitionClass = $ definitionDecorator ;
4039 }
40+
41+ $ providerId = 'security.authentication.provider.fos_oauth_server. ' .$ id ;
4142 $ container
42- ->setDefinition ($ providerId , $ definition )
43+ ->setDefinition ($ providerId , new $ definitionClass ( ' fos_oauth_server.security.authentication.provider ' ) )
4344 ->replaceArgument (0 , new Reference ($ userProvider ));
4445
4546 $ listenerId = 'security.authentication.listener.fos_oauth_server. ' .$ id ;
46-
47- if (class_exists (ChildDefinition::class)) {
48- $ definition = new ChildDefinition ('fos_oauth_server.security.authentication.listener ' );
49- } else {
50- $ definition = new DefinitionDecorator ('fos_oauth_server.security.authentication.listener ' );
51- }
52- $ container ->setDefinition ($ listenerId , $ definition );
47+ $ container ->setDefinition ($ listenerId , new $ definitionClass ('fos_oauth_server.security.authentication.listener ' ));
5348
5449 return [$ providerId , $ listenerId , 'fos_oauth_server.security.entry_point ' ];
5550 }
0 commit comments