1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ma27\ApiKeyAuthenticationBundle\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Compiler pass which gathers hasher services and keeps them inside a private parameter. |
10
|
|
|
* The configuration can declare which hash service to use and this one will be fetched from the parameter. |
11
|
|
|
* |
12
|
|
|
* @internal |
13
|
|
|
*/ |
14
|
|
|
class CompileHasherServicesPass implements CompilerPassInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
* |
19
|
|
|
* @throws \LogicException If multiple tags at one service exist. |
20
|
|
|
* @throws \LogicException If no appropriate tag is given. |
21
|
|
|
* @throws \LogicException If no alias is given. |
22
|
|
|
*/ |
23
|
12 |
|
public function process(ContainerBuilder $container) |
24
|
|
|
{ |
25
|
12 |
|
if (!$container->hasParameter('ma27_api_key_authentication.password_hashing_service')) { |
26
|
1 |
|
return; |
27
|
|
|
} |
28
|
|
|
|
29
|
11 |
|
$alias = $container->getParameter('ma27_api_key_authentication.password_hashing_service'); |
30
|
11 |
|
foreach ($container->findTaggedServiceIds('ma27_api_key_authentication.password_hasher') as $id => $tags) { |
31
|
11 |
|
if (count($tags) > 1) { |
32
|
1 |
|
throw new \LogicException(sprintf( |
33
|
1 |
|
'Service "%s" can have the tag "%s" only one time!', |
34
|
1 |
|
$id, |
35
|
1 |
|
'ma27_api_key_authentication.password_hasher' |
36
|
|
|
)); |
37
|
|
|
} |
38
|
|
|
|
39
|
10 |
|
if (!array_key_exists('alias', $tags[0])) { |
40
|
1 |
|
throw new \LogicException(sprintf( |
41
|
1 |
|
'The tag "%s" on service "%s" needs an `alias` property!', |
42
|
1 |
|
'ma27_api_key_authentication.password_hasher', |
43
|
1 |
|
$id |
44
|
|
|
)); |
45
|
|
|
} |
46
|
|
|
|
47
|
9 |
|
if ($tags[0]['alias'] === $alias) { |
48
|
8 |
|
$container->setAlias('ma27_api_key_authentication.password.strategy', $id); |
49
|
|
|
|
50
|
9 |
|
return; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
throw new \LogicException(sprintf( |
55
|
1 |
|
'No service found for hashing alias "%s"!', |
56
|
1 |
|
$alias |
57
|
|
|
)); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|