1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yokai\SecurityTokenBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\Config\FileLocator; |
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
10
|
|
|
use Yokai\SecurityTokenBundle\Archive\ArchivistInterface; |
11
|
|
|
use Yokai\SecurityTokenBundle\DependencyInjection\Factory\TokenConfigurationFactory; |
12
|
|
|
use Yokai\SecurityTokenBundle\Factory\TokenFactoryInterface; |
13
|
|
|
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesserInterface; |
14
|
|
|
use Yokai\SecurityTokenBundle\Manager\TokenManagerInterface; |
15
|
|
|
use Yokai\SecurityTokenBundle\Manager\UserManagerInterface; |
16
|
|
|
use Yokai\SecurityTokenBundle\Repository\TokenRepositoryInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Yann Eugoné <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class YokaiSecurityTokenExtension extends Extension |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
4 |
|
public function load(array $configs, ContainerBuilder $container) |
27
|
|
|
{ |
28
|
4 |
|
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs); |
|
|
|
|
29
|
|
|
|
30
|
4 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
31
|
4 |
|
$loader->load('services.xml'); |
32
|
|
|
|
33
|
4 |
|
$this->registerTokens($config, $container); |
34
|
4 |
|
$this->registerAliases($config, $container); |
35
|
4 |
|
$this->registerAutoconfigureAliases($container); |
36
|
4 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param array $config |
40
|
|
|
* @param ContainerBuilder $container |
41
|
|
|
*/ |
42
|
4 |
|
private function registerTokens(array $config, ContainerBuilder $container) |
43
|
|
|
{ |
44
|
4 |
|
foreach ($config['tokens'] as $name => $token) { |
45
|
3 |
|
TokenConfigurationFactory::create( |
46
|
3 |
|
$name, |
47
|
3 |
|
$token['generator'], |
48
|
3 |
|
$token['duration'], |
49
|
3 |
|
$token['usages'], |
50
|
3 |
|
$token['keep'], |
51
|
3 |
|
$token['unique'], |
52
|
3 |
|
$container |
53
|
|
|
); |
54
|
|
|
} |
55
|
4 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param array $config |
59
|
|
|
* @param ContainerBuilder $container |
60
|
|
|
*/ |
61
|
4 |
|
private function registerAliases(array $config, ContainerBuilder $container) |
62
|
|
|
{ |
63
|
4 |
|
$aliasExists = class_exists('Symfony\Component\DependencyInjection\Alias'); |
64
|
4 |
|
$isTest = $container->getParameter('kernel.environment') === 'test'; |
65
|
|
|
|
66
|
4 |
|
foreach ($config['services'] as $name => $service) { |
67
|
4 |
|
$alias = $container->setAlias(sprintf('yokai_security_token.%s', $name), $service); |
68
|
4 |
|
if ($aliasExists && $alias instanceof Alias && $isTest) { |
69
|
|
|
$alias->setPublic(true); |
70
|
|
|
} |
71
|
|
|
} |
72
|
4 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param ContainerBuilder $container |
76
|
|
|
*/ |
77
|
4 |
|
private function registerAutoconfigureAliases(ContainerBuilder $container) |
78
|
|
|
{ |
79
|
|
|
$interfaceMap = [ |
80
|
4 |
|
'information_guesser' => InformationGuesserInterface::class, |
81
|
|
|
'token_factory' => TokenFactoryInterface::class, |
82
|
|
|
'token_repository' => TokenRepositoryInterface::class, |
83
|
|
|
'token_manager' => TokenManagerInterface::class, |
84
|
|
|
'user_manager' => UserManagerInterface::class, |
85
|
|
|
'archivist' => ArchivistInterface::class, |
86
|
|
|
]; |
87
|
|
|
|
88
|
4 |
|
foreach ($interfaceMap as $service => $interface) { |
89
|
4 |
|
$container->setAlias($interface, sprintf('yokai_security_token.%s', $service)); |
90
|
|
|
} |
91
|
4 |
|
} |
92
|
|
|
} |
93
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: