15
15
16
16
use Symfony \Bundle \SecurityBundle \DependencyInjection \Security \Factory \SecurityFactoryInterface ;
17
17
use Symfony \Component \Config \Definition \Builder \NodeDefinition ;
18
- use Symfony \Component \DependencyInjection \ChildDefinition ;
19
18
use Symfony \Component \DependencyInjection \ContainerBuilder ;
20
- use Symfony \Component \DependencyInjection \DefinitionDecorator ;
21
19
use Symfony \Component \DependencyInjection \Reference ;
22
20
23
21
/**
@@ -32,24 +30,21 @@ class OAuthFactory implements SecurityFactoryInterface
32
30
*/
33
31
public function create (ContainerBuilder $ container , $ id , $ config , $ userProvider , $ defaultEntryPoint )
34
32
{
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 ;
40
39
}
40
+
41
+ $ providerId = 'security.authentication.provider.fos_oauth_server. ' .$ id ;
41
42
$ container
42
- ->setDefinition ($ providerId , $ definition )
43
+ ->setDefinition ($ providerId , new $ definitionClass ( ' fos_oauth_server.security.authentication.provider ' ) )
43
44
->replaceArgument (0 , new Reference ($ userProvider ));
44
45
45
46
$ 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 ' ));
53
48
54
49
return [$ providerId , $ listenerId , 'fos_oauth_server.security.entry_point ' ];
55
50
}
0 commit comments