Failed Conditions
Push — master ( 6560de...8483ce )
by Florent
05:17
created

JWEDecrypter::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Source;
17
use Jose\Component\Encryption\JWEDecrypterFactory;
18
use Jose\Component\Encryption\JWEDecrypter as JWEDecrypterService;
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 JWEDecrypter.
26
 */
27
final class JWEDecrypter implements Source
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function name(): string
33
    {
34
        return 'jwe_decrypters';
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.jwe_decrypter.%s', $name);
44
            $definition = new Definition(JWEDecrypterService::class);
45
            $definition
46
                ->setFactory([new Reference(JWEDecrypterFactory::class), 'create'])
47
                ->setArguments([
48
                    $itemConfig['key_encryption_algorithms'],
49
                    $itemConfig['content_encryption_algorithms'],
50
                    $itemConfig['compression_methods'],
51
                ])
52
                ->addTag('jose.jwe_decrypter')
53
                ->setPublic($itemConfig['is_public']);
54
55
            $container->setDefinition($service_id, $definition);
56
        }
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getNodeDefinition(ArrayNodeDefinition $node)
63
    {
64
        $node
65
            ->children()
66
                ->arrayNode($this->name())
67
                    ->useAttributeAsKey('name')
68
                    ->prototype('array')
69
                        ->children()
70
                            ->booleanNode('is_public')
71
                                ->info('If true, the service will be public, else private.')
72
                                ->defaultTrue()
73
                            ->end()
74
                            ->arrayNode('key_encryption_algorithms')
75
                                ->info('A list of supported key encryption algorithms.')
76
                                ->useAttributeAsKey('name')
77
                                ->isRequired()
78
                                ->prototype('scalar')->end()
79
                            ->end()
80
                            ->arrayNode('content_encryption_algorithms')
81
                                ->info('A list of supported content encryption algorithms.')
82
                                ->useAttributeAsKey('name')
83
                                ->isRequired()
84
                                ->prototype('scalar')->end()
85
                            ->end()
86
                            ->arrayNode('compression_methods')
87
                                ->info('A list of supported compression methods.')
88
                                ->useAttributeAsKey('name')
89
                                ->defaultValue(['DEF'])
90
                                ->prototype('scalar')->end()
91
                            ->end()
92
                        ->end()
93
                    ->end()
94
                ->end()
95
            ->end();
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function prepend(ContainerBuilder $container, array $config): ?array
102
    {
103
        return null;
104
    }
105
}
106