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