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\Checker\DependencyInjection\Source; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\DependencyInjection\Source\SourceInterface; |
17
|
|
|
use Jose\Component\Checker\ClaimCheckerManagerFactory; |
18
|
|
|
use Jose\Component\Signature\JWSLoader as JWSLoaderService; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
22
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class JWSLoader. |
26
|
|
|
*/ |
27
|
|
|
final class ClaimChecker implements SourceInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function name(): string |
33
|
|
|
{ |
34
|
|
|
return 'claim_checkers'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function load(array $configs, ContainerBuilder $container) |
41
|
|
|
{ |
42
|
|
|
$this->createService($configs[$this->name()], $container); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
private function createService(array $config, ContainerBuilder $container) |
49
|
|
|
{ |
50
|
|
|
foreach ($config as $name => $itemConfig) { |
51
|
|
|
$service_id = sprintf('jose.claim_checker.%s', $name); |
52
|
|
|
$definition = new Definition(JWSLoaderService::class); |
53
|
|
|
$definition |
54
|
|
|
->setFactory([new Reference(ClaimCheckerManagerFactory::class), 'create']) |
55
|
|
|
->setArguments([ |
56
|
|
|
$itemConfig['claims'], |
57
|
|
|
]) |
58
|
|
|
->setPublic($itemConfig['is_public']); |
59
|
|
|
|
60
|
|
|
$container->setDefinition($service_id, $definition); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node) |
68
|
|
|
{ |
69
|
|
|
$node |
70
|
|
|
->children() |
71
|
|
|
->arrayNode($this->name()) |
72
|
|
|
->useAttributeAsKey('name') |
73
|
|
|
->prototype('array') |
74
|
|
|
->children() |
75
|
|
|
->booleanNode('is_public') |
76
|
|
|
->info('If true, the service will be public, else private.') |
77
|
|
|
->defaultTrue() |
78
|
|
|
->end() |
79
|
|
|
->arrayNode('claims') |
80
|
|
|
->useAttributeAsKey('name') |
81
|
|
|
->isRequired() |
82
|
|
|
->prototype('scalar')->end() |
83
|
|
|
->end() |
84
|
|
|
->end() |
85
|
|
|
->end() |
86
|
|
|
->end() |
87
|
|
|
->end(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function prepend(ContainerBuilder $container, array $config): ?array |
94
|
|
|
{ |
95
|
|
|
return null; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|