Skip to content

Commit

Permalink
Dont use DefinitionDecorator on symfony 3.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Jun 28, 2017
1 parent d2d3fc3 commit 2c9a3df
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions DependencyInjection/Security/Factory/JWTFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -22,12 +23,12 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
{
$providerId = 'security.authentication.provider.jwt.' . $id;
$container
->setDefinition($providerId, new DefinitionDecorator($config['authentication_provider']))
->setDefinition($providerId, $this->createChildDefinition($config['authentication_provider']))
->replaceArgument(0, new Reference($userProvider));

$listenerId = 'security.authentication.listener.jwt.' . $id;
$container
->setDefinition($listenerId, new DefinitionDecorator($config['authentication_listener']))
->setDefinition($listenerId, $this->createChildDefinition($config['authentication_listener']))
->replaceArgument(2, $config);

$entryPointId = $defaultEntryPoint;
Expand All @@ -40,7 +41,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,

$authorizationHeaderExtractorId = 'lexik_jwt_authentication.extractor.authorization_header_extractor.' . $id;
$container
->setDefinition($authorizationHeaderExtractorId, new DefinitionDecorator('lexik_jwt_authentication.extractor.authorization_header_extractor'))
->setDefinition($authorizationHeaderExtractorId, $this->createChildDefinition('lexik_jwt_authentication.extractor.authorization_header_extractor'))
->replaceArgument(0, $config['authorization_header']['prefix'])
->replaceArgument(1, $config['authorization_header']['name']);

Expand All @@ -54,7 +55,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,

$queryParameterExtractorId = 'lexik_jwt_authentication.extractor.query_parameter_extractor.' . $id;
$container
->setDefinition($queryParameterExtractorId, new DefinitionDecorator('lexik_jwt_authentication.extractor.query_parameter_extractor'))
->setDefinition($queryParameterExtractorId, $this->createChildDefinition('lexik_jwt_authentication.extractor.query_parameter_extractor'))
->replaceArgument(0, $config['query_parameter']['name']);

$container
Expand All @@ -67,7 +68,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,

$cookieExtractorId = 'lexik_jwt_authentication.extractor.cookie_extractor.' . $id;
$container
->setDefinition($cookieExtractorId, new DefinitionDecorator('lexik_jwt_authentication.extractor.cookie_extractor'))
->setDefinition($cookieExtractorId, $this->createChildDefinition('lexik_jwt_authentication.extractor.cookie_extractor'))
->replaceArgument(0, $config['cookie']['name']);

$container
Expand Down Expand Up @@ -165,8 +166,17 @@ public function addConfiguration(NodeDefinition $node)
protected function createEntryPoint(ContainerBuilder $container, $id, $defaultEntryPoint)
{
$entryPointId = 'lexik_jwt_authentication.security.authentication.entry_point.'.$id;
$container->setDefinition($entryPointId, new DefinitionDecorator('lexik_jwt_authentication.security.authentication.entry_point'));
$container->setDefinition($entryPointId, $this->createChildDefinition('lexik_jwt_authentication.security.authentication.entry_point'));

return $entryPointId;
}

private function createChildDefinition($parent)
{
if (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) {
return new ChildDefinition($parent);
}

return new DefinitionDecorator($parent);
}
}

0 comments on commit 2c9a3df

Please sign in to comment.