Skip to content

Commit 31ff637

Browse files
committed
fix: OAuthFactory node definition, DefinitionDecorator deprecated in SF4
1 parent 06542af commit 31ff637

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

DependencyInjection/Security/Factory/OAuthFactory.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
1717
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
18-
use Symfony\Component\DependencyInjection\ChildDefinition;
1918
use Symfony\Component\DependencyInjection\ContainerBuilder;
20-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
2119
use 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

Comments
 (0)