1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2019 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\Source\Signature; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Source; |
17
|
|
|
use Jose\Bundle\JoseFramework\Services\JWSLoaderFactory; |
18
|
|
|
use Jose\Component\Signature\JWSLoader as JWSLoaderService; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
22
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
23
|
|
|
|
24
|
|
|
class JWSLoader implements Source |
25
|
|
|
{ |
26
|
|
|
public function name(): string |
27
|
|
|
{ |
28
|
|
|
return 'loaders'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
32
|
|
|
{ |
33
|
|
|
foreach ($configs[$this->name()] as $name => $itemConfig) { |
34
|
|
|
$service_id = sprintf('jose.jws_loader.%s', $name); |
35
|
|
|
$definition = new Definition(JWSLoaderService::class); |
36
|
|
|
$definition |
37
|
|
|
->setFactory([new Reference(JWSLoaderFactory::class), 'create']) |
38
|
|
|
->setArguments([ |
39
|
|
|
$itemConfig['serializers'], |
40
|
|
|
$itemConfig['signature_algorithms'], |
41
|
|
|
$itemConfig['header_checkers'], |
42
|
|
|
]) |
43
|
|
|
->addTag('jose.jws_loader') |
44
|
|
|
->setPublic($itemConfig['is_public']) |
45
|
|
|
; |
46
|
|
|
foreach ($itemConfig['tags'] as $id => $attributes) { |
47
|
|
|
$definition->addTag($id, $attributes); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$container->setDefinition($service_id, $definition); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getNodeDefinition(NodeDefinition $node): void |
55
|
|
|
{ |
56
|
|
|
$node |
57
|
|
|
->children() |
58
|
|
|
->arrayNode($this->name()) |
59
|
|
|
->requiresAtLeastOneElement() |
60
|
|
|
->useAttributeAsKey('name') |
61
|
|
|
->arrayPrototype() |
62
|
|
|
->children() |
63
|
|
|
->booleanNode('is_public') |
64
|
|
|
->info('If true, the service will be public, else private.') |
65
|
|
|
->defaultTrue() |
66
|
|
|
->end() |
67
|
|
|
->arrayNode('signature_algorithms') |
68
|
|
|
->info('A list of signature algorithm aliases.') |
69
|
|
|
->useAttributeAsKey('name') |
70
|
|
|
->isRequired() |
71
|
|
|
->scalarPrototype()->end() |
72
|
|
|
->end() |
73
|
|
|
->arrayNode('serializers') |
74
|
|
|
->info('A list of signature serializer aliases.') |
75
|
|
|
->useAttributeAsKey('name') |
76
|
|
|
->requiresAtLeastOneElement() |
77
|
|
|
->scalarPrototype()->end() |
78
|
|
|
->end() |
79
|
|
|
->arrayNode('header_checkers') |
80
|
|
|
->info('A list of header checker aliases.') |
81
|
|
|
->useAttributeAsKey('name') |
82
|
|
|
->treatNullLike([]) |
83
|
|
|
->treatFalseLike([]) |
84
|
|
|
->scalarPrototype()->end() |
85
|
|
|
->end() |
86
|
|
|
->arrayNode('tags') |
87
|
|
|
->info('A list of tags to be associated to the service.') |
88
|
|
|
->useAttributeAsKey('name') |
89
|
|
|
->treatNullLike([]) |
90
|
|
|
->treatFalseLike([]) |
91
|
|
|
->variablePrototype()->end() |
92
|
|
|
->end() |
93
|
|
|
->end() |
94
|
|
|
->end() |
95
|
|
|
->end() |
96
|
|
|
->end() |
97
|
|
|
; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
101
|
|
|
{ |
102
|
|
|
return []; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|