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
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
public function process(ContainerBuilder $container) |
26
|
|
|
{ |
27
|
|
|
if (!$container->hasDefinition('jose.checker_manager')) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$definition = $container->getDefinition('jose.checker_manager'); |
32
|
|
|
|
33
|
|
|
$this->addClaimCheckers($definition, $container); |
34
|
|
|
$this->addHeaderCheckers($definition, $container); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param \Symfony\Component\DependencyInjection\Definition $definition |
39
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
40
|
|
|
*/ |
41
|
|
|
private function addHeaderCheckers(Definition $definition, ContainerBuilder $container) |
42
|
|
|
{ |
43
|
|
|
$taggedHeaderCheckerServices = $container->findTaggedServiceIds('jose.checker.header'); |
44
|
|
|
foreach ($taggedHeaderCheckerServices as $id => $tags) { |
45
|
|
|
foreach ($tags as $attributes) { |
46
|
|
|
Assertion::keyExists($attributes, 'alias', sprintf("The header checker '%s' does not have any 'alias' attribute.", $id)); |
47
|
|
|
$definition->addMethodCall('addHeaderChecker', [new Reference($id), $attributes['alias']]); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param \Symfony\Component\DependencyInjection\Definition $definition |
54
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
55
|
|
|
*/ |
56
|
|
|
private function addClaimCheckers(Definition $definition, ContainerBuilder $container) |
57
|
|
|
{ |
58
|
|
|
$taggedClaimCheckerServices = $container->findTaggedServiceIds('jose.checker.claim'); |
59
|
|
|
foreach ($taggedClaimCheckerServices as $id => $tags) { |
60
|
|
|
foreach ($tags as $attributes) { |
61
|
|
|
Assertion::keyExists($attributes, 'alias', sprintf("The claim checker '%s' does not have any 'alias' attribute.", $id)); |
62
|
|
|
$definition->addMethodCall('addClaimChecker', [new Reference($id), $attributes['alias']]); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|