1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the GesdinetJWTRefreshTokenBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Gesdinet <http://www.gesdinet.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
15
|
|
|
use Symfony\Component\Config\FileLocator; |
16
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This is the class that loads and manages your bundle configuration. |
21
|
|
|
* |
22
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
23
|
|
|
*/ |
24
|
|
|
class GesdinetJWTRefreshTokenExtension extends Extension |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
30
|
|
|
{ |
31
|
1 |
|
$configuration = new Configuration(); |
32
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
33
|
|
|
|
34
|
1 |
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
35
|
1 |
|
$loader->load('services.yml'); |
36
|
|
|
|
37
|
1 |
|
$container->setParameter('gesdinet_jwt_refresh_token.ttl', $config['ttl']); |
38
|
1 |
|
$container->setParameter('gesdinet_jwt_refresh_token.ttl_update', $config['ttl_update']); |
39
|
1 |
|
$container->setParameter('gesdinet_jwt_refresh_token.security.firewall', $config['firewall']); |
40
|
1 |
|
$container->setParameter('gesdinet_jwt_refresh_token.user_provider', $config['user_provider']); |
41
|
|
|
$container->setParameter('gesdinet_jwt_refresh_token.user_identity_field', $config['user_identity_field']); |
42
|
|
|
|
43
|
1 |
|
$refreshTokenClass = 'Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken'; |
44
|
|
|
$objectManager = 'doctrine.orm.entity_manager'; |
45
|
|
|
|
46
|
|
|
if ('mongodb' === strtolower($config['manager_type'])) { |
47
|
1 |
|
$refreshTokenClass = 'Gesdinet\JWTRefreshTokenBundle\Document\RefreshToken'; |
48
|
1 |
|
$objectManager = 'doctrine_mongodb.odm.document_manager'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (null !== $this->getRefreshTokenClass($config)) { |
52
|
|
|
$refreshTokenClass = $this->getRefreshTokenClass($config); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (null !== $this->getObjectManager($config)) { |
56
|
|
|
$objectManager = $this->getObjectManager($config); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$container->setParameter('gesdinet.jwtrefreshtoken.refresh_token.class', $refreshTokenClass); |
60
|
|
|
$container->setParameter('gesdinet.jwtrefreshtoken.object_manager.id', $objectManager); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get refresh token class from configuration. |
65
|
|
|
* |
66
|
|
|
* Supports deprecated configuration |
67
|
|
|
* |
68
|
|
|
* @param array $config |
69
|
|
|
* |
70
|
|
|
* @return string|null |
71
|
|
|
*/ |
72
|
|
|
protected function getRefreshTokenClass(array $config) |
73
|
|
|
{ |
74
|
|
|
if (isset($config['refresh_token_class'])) { |
75
|
|
|
return $config['refresh_token_class']; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $config['refresh_token_entity'] ?: null; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get object manager from configuration. |
83
|
|
|
* |
84
|
|
|
* Supports deprecated configuration |
85
|
|
|
* |
86
|
|
|
* @param array $config |
87
|
|
|
* |
88
|
|
|
* @return string|null |
89
|
|
|
*/ |
90
|
|
|
protected function getObjectManager(array $config) |
91
|
|
|
{ |
92
|
|
|
if (isset($config['object_manager'])) { |
93
|
|
|
return $config['object_manager']; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $objectManager = $config['entity_manager'] ?: null; |
|
|
|
|
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.