1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License (MIT) |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
7
|
|
|
* |
8
|
|
|
* This software may be modified and distributed under the terms |
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace SpomkyLabs\JoseBundle\DependencyInjection\Source; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
18
|
|
|
|
19
|
|
|
final class EncrypterSource implements SourceInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function getName() |
25
|
|
|
{ |
26
|
|
|
return 'encrypters'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function createService($name, array $config, ContainerBuilder $container) |
33
|
|
|
{ |
34
|
|
|
$service_id = sprintf('jose.encrypter.%s', $name); |
35
|
|
|
$definition = new Definition('Jose\Encrypter'); |
36
|
|
|
$definition->setFactory([ |
37
|
|
|
new Reference('jose.factory.service'), |
38
|
|
|
'createEncrypter', |
39
|
|
|
]); |
40
|
|
|
$definition->setArguments([ |
41
|
|
|
$config['key_encryption_algorithms'], |
42
|
|
|
$config['content_encryption_algorithms'], |
43
|
|
|
$config['compression_methods'], |
44
|
|
|
]); |
45
|
|
|
$definition->setPublic($config['is_public']); |
46
|
|
|
|
47
|
|
|
$container->setDefinition($service_id, $definition); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node) |
54
|
|
|
{ |
55
|
|
|
$node |
56
|
|
|
->children() |
57
|
|
|
->arrayNode($this->getName()) |
58
|
|
|
->useAttributeAsKey('name') |
59
|
|
|
->prototype('array') |
60
|
|
|
->children() |
61
|
|
|
->booleanNode('is_public') |
62
|
|
|
->info('If true, the service will be public, else private.') |
63
|
|
|
->defaultTrue() |
64
|
|
|
->end() |
65
|
|
|
->arrayNode('key_encryption_algorithms') |
66
|
|
|
->useAttributeAsKey('name') |
67
|
|
|
->isRequired() |
68
|
|
|
->prototype('scalar')->end() |
69
|
|
|
->end() |
70
|
|
|
->arrayNode('content_encryption_algorithms') |
71
|
|
|
->useAttributeAsKey('name') |
72
|
|
|
->isRequired() |
73
|
|
|
->prototype('scalar')->end() |
74
|
|
|
->end() |
75
|
|
|
->arrayNode('compression_methods') |
76
|
|
|
->useAttributeAsKey('name') |
77
|
|
|
->defaultValue(['DEF']) |
78
|
|
|
->prototype('scalar')->end() |
79
|
|
|
->end() |
80
|
|
|
->booleanNode('create_decrypter') |
81
|
|
|
->defaultFalse() |
82
|
|
|
->end() |
83
|
|
|
->end() |
84
|
|
|
->end() |
85
|
|
|
->end() |
86
|
|
|
->end(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function prepend(ContainerBuilder $container, array $config) |
93
|
|
|
{ |
94
|
|
|
if (false === array_key_exists($this->getName(), $config)) { |
95
|
|
|
return; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
foreach ($config[$this->getName()] as $id => $section) { |
99
|
|
|
if (true === $section['create_decrypter']) { |
100
|
|
|
$values = $section; |
101
|
|
|
unset($values['create_decrypter']); |
102
|
|
|
$config['decrypters'] = array_merge( |
103
|
|
|
array_key_exists('decrypters', $config) ? $config['decrypters'] : [], |
104
|
|
|
[$id => $values] |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $config; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|