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\Encryption\DependencyInjection\Source; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\DependencyInjection\Source\SourceInterface; |
17
|
|
|
use Jose\Component\Encryption\JWEBuilderFactory; |
18
|
|
|
use Jose\Component\Encryption\JWEBuilder as JWEBuilderService; |
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 JWEBuilder. |
26
|
|
|
*/ |
27
|
|
|
final class JWEBuilder implements SourceInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function name(): string |
33
|
|
|
{ |
34
|
|
|
return 'jwe_builders'; |
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.jwe_builder.%s', $name); |
52
|
|
|
$definition = new Definition(JWEBuilderService::class); |
53
|
|
|
$definition |
54
|
|
|
->setFactory([new Reference(JWEBuilderFactory::class), 'create']) |
55
|
|
|
->setArguments([ |
56
|
|
|
$itemConfig['key_encryption_algorithms'], |
57
|
|
|
$itemConfig['content_encryption_algorithms'], |
58
|
|
|
$itemConfig['compression_methods'], |
59
|
|
|
]) |
60
|
|
|
->setPublic($itemConfig['is_public']); |
61
|
|
|
|
62
|
|
|
$container->setDefinition($service_id, $definition); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node) |
70
|
|
|
{ |
71
|
|
|
$node |
72
|
|
|
->children() |
73
|
|
|
->arrayNode($this->name()) |
74
|
|
|
->useAttributeAsKey('name') |
75
|
|
|
->prototype('array') |
76
|
|
|
->children() |
77
|
|
|
->booleanNode('is_public') |
78
|
|
|
->info('If true, the service will be public, else private.') |
79
|
|
|
->defaultTrue() |
80
|
|
|
->end() |
81
|
|
|
->arrayNode('key_encryption_algorithms') |
82
|
|
|
->info('A list of supported key encryption algorithms.') |
83
|
|
|
->useAttributeAsKey('name') |
84
|
|
|
->isRequired() |
85
|
|
|
->prototype('scalar')->end() |
86
|
|
|
->end() |
87
|
|
|
->arrayNode('content_encryption_algorithms') |
88
|
|
|
->info('A list of supported content encryption algorithms.') |
89
|
|
|
->useAttributeAsKey('name') |
90
|
|
|
->isRequired() |
91
|
|
|
->prototype('scalar')->end() |
92
|
|
|
->end() |
93
|
|
|
->arrayNode('compression_methods') |
94
|
|
|
->info('A list of supported compression methods.') |
95
|
|
|
->useAttributeAsKey('name') |
96
|
|
|
->defaultValue(['DEF']) |
97
|
|
|
->prototype('scalar')->end() |
98
|
|
|
->end() |
99
|
|
|
->end() |
100
|
|
|
->end() |
101
|
|
|
->end() |
102
|
|
|
->end(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function prepend(ContainerBuilder $container, array $config): ?array |
109
|
|
|
{ |
110
|
|
|
return null; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|