|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License (MIT) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
|
7
|
|
|
* |
|
8
|
|
|
* This software may be modified and distributed under the terms |
|
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace SpomkyLabs\JoseBundle\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Assert\Assertion; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
19
|
|
|
|
|
20
|
|
|
final class CheckerCompilerPass implements CompilerPassInterface |
|
21
|
|
|
{ |
|
22
|
|
|
public function process(ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
|
|
if (!$container->hasDefinition('jose.checker_manager')) { |
|
25
|
|
|
return; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$definition = $container->getDefinition('jose.checker_manager'); |
|
29
|
|
|
|
|
30
|
|
|
$this->addClaimCheckers($definition, $container); |
|
31
|
|
|
$this->addHeaderCheckers($definition, $container); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param \Symfony\Component\DependencyInjection\Definition $definition |
|
36
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
37
|
|
|
*/ |
|
38
|
|
|
private function addHeaderCheckers(Definition $definition, ContainerBuilder $container) |
|
39
|
|
|
{ |
|
40
|
|
|
$taggedHeaderCheckerServices = $container->findTaggedServiceIds('jose.checker.header'); |
|
41
|
|
|
foreach ($taggedHeaderCheckerServices as $id => $tags) { |
|
42
|
|
|
foreach ($tags as $attributes) { |
|
43
|
|
|
Assertion::keyExists($attributes, 'alias', sprintf("The header checker '%s' does not have any 'alias' attribute.", $id)); |
|
44
|
|
|
$definition->addMethodCall('addHeaderChecker', [new Reference($id), $attributes['alias']]); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param \Symfony\Component\DependencyInjection\Definition $definition |
|
51
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
52
|
|
|
*/ |
|
53
|
|
|
private function addClaimCheckers(Definition $definition, ContainerBuilder $container) |
|
54
|
|
|
{ |
|
55
|
|
|
$taggedClaimCheckerServices = $container->findTaggedServiceIds('jose.checker.claim'); |
|
56
|
|
|
foreach ($taggedClaimCheckerServices as $id => $tags) { |
|
57
|
|
|
foreach ($tags as $attributes) { |
|
58
|
|
|
Assertion::keyExists($attributes, 'alias', sprintf("The claim checker '%s' does not have any 'alias' attribute.", $id)); |
|
59
|
|
|
$definition->addMethodCall('addClaimChecker', [new Reference($id), $attributes['alias']]); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|