1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 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\Component\Signature\Serializer\JWSSerializerManager; |
18
|
|
|
use Jose\Component\Signature\Serializer\JWSSerializerManagerFactory; |
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 JWSSerializer. |
26
|
|
|
*/ |
27
|
|
|
final class JWSSerializer implements Source |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function name(): string |
33
|
|
|
{ |
34
|
|
|
return 'serializers'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function load(array $configs, ContainerBuilder $container) |
41
|
|
|
{ |
42
|
|
|
foreach ($configs[$this->name()] as $name => $itemConfig) { |
43
|
|
|
$service_id = sprintf('jose.jws_serializer.%s', $name); |
44
|
|
|
$definition = new Definition(JWSSerializerManager::class); |
45
|
|
|
$definition |
46
|
|
|
->setFactory([new Reference(JWSSerializerManagerFactory::class), 'create']) |
47
|
|
|
->setArguments([$itemConfig['serializers']]) |
48
|
|
|
->addTag('jose.jws_serializer_manager') |
49
|
|
|
->setPublic($itemConfig['is_public']); |
50
|
|
|
foreach ($itemConfig['tags'] as $id => $attributes) { |
51
|
|
|
$definition->addTag($id, $attributes); |
52
|
|
|
} |
53
|
|
|
$container->setDefinition($service_id, $definition); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node) |
61
|
|
|
{ |
62
|
|
|
$node |
63
|
|
|
->children() |
64
|
|
|
->arrayNode($this->name()) |
65
|
|
|
->useAttributeAsKey('name') |
66
|
|
|
->prototype('array') |
67
|
|
|
->children() |
68
|
|
|
->booleanNode('is_public') |
69
|
|
|
->info('If true, the service will be public, else private.') |
70
|
|
|
->defaultTrue() |
71
|
|
|
->end() |
72
|
|
|
->arrayNode('serializers') |
73
|
|
|
->info('A list of JWS serializers aliases.') |
74
|
|
|
->useAttributeAsKey('name') |
75
|
|
|
->treatNullLike(['jws_compact']) |
76
|
|
|
->prototype('scalar')->end() |
77
|
|
|
->end() |
78
|
|
|
->arrayNode('tags') |
79
|
|
|
->info('A list of tags to be associated to the service.') |
80
|
|
|
->useAttributeAsKey('name') |
81
|
|
|
->treatNullLike([]) |
82
|
|
|
->treatFalseLike([]) |
83
|
|
|
->prototype('variable')->end() |
84
|
|
|
->end() |
85
|
|
|
->end() |
86
|
|
|
->end() |
87
|
|
|
->end() |
88
|
|
|
->end(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
95
|
|
|
{ |
96
|
|
|
return []; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|