Failed Conditions
Push — v7 ( e446d4...9b9adb )
by Florent
02:29
created

JWELoader::getNodeDefinition()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

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