1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Bundle\JoseFramework\DependencyInjection\Compiler; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\DataCollector\KeyCollector; |
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
20
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class KeyCollectorCompilerPass. |
24
|
|
|
*/ |
25
|
|
|
final class KeyCollectorCompilerPass implements CompilerPassInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function process(ContainerBuilder $container) |
31
|
|
|
{ |
32
|
|
|
if (!$container->hasDefinition(KeyCollector::class)) { |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$definition = $container->getDefinition(KeyCollector::class); |
37
|
|
|
|
38
|
|
|
$services = [ |
39
|
|
|
'addJWK' => 'jose.jwk', |
40
|
|
|
'addJWKSet' => 'jose.jwkset', |
41
|
|
|
]; |
42
|
|
|
foreach ($services as $method => $tag) { |
43
|
|
|
$this->collectServices($method, $tag, $definition, $container); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $method |
49
|
|
|
* @param string $tag |
50
|
|
|
* @param Definition $definition |
51
|
|
|
* @param ContainerBuilder $container |
52
|
|
|
*/ |
53
|
|
|
private function collectServices(string $method, string $tag, Definition $definition, ContainerBuilder $container) |
54
|
|
|
{ |
55
|
|
|
$taggedJWSServices = $container->findTaggedServiceIds($tag); |
56
|
|
|
foreach ($taggedJWSServices as $id => $tags) { |
57
|
|
|
$definition->addMethodCall($method, [$id, new Reference($id)]); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|