Failed Conditions
Push — v7 ( 0b3eb8...e446d4 )
by Florent
02:45
created

JWEBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 76
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A createService() 0 15 1
B getNodeDefinition() 0 35 1
A prepend() 0 4 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\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
final class JWEBuilder implements SourceInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function name(): string
30
    {
31
        return 'jwe_builders';
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function createService(string $name, array $config, ContainerBuilder $container)
38
    {
39
        $service_id = sprintf('jose.jwe_builder.%s', $name);
40
        $definition = new Definition(JWEBuilderService::class);
41
        $definition
42
            ->setFactory([new Reference(JWEBuilderFactory::class), 'create'])
43
            ->setArguments([
44
                $config['key_encryption_algorithms'],
45
                $config['content_encryption_algorithms'],
46
                $config['compression_methods']
47
            ])
48
            ->setPublic($config['is_public']);
49
50
        $container->setDefinition($service_id, $definition);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getNodeDefinition(ArrayNodeDefinition $node)
57
    {
58
        $node
59
            ->children()
60
                ->arrayNode($this->name())
61
                    ->useAttributeAsKey('name')
62
                    ->prototype('array')
63
                        ->children()
64
                            ->booleanNode('is_public')
65
                                ->info('If true, the service will be public, else private.')
66
                                ->defaultTrue()
67
                            ->end()
68
                            ->arrayNode('key_encryption_algorithms')
69
                                ->info('A list of supported key encryption algorithms.')
70
                                ->useAttributeAsKey('name')
71
                                ->isRequired()
72
                                ->prototype('scalar')->end()
73
                            ->end()
74
                            ->arrayNode('content_encryption_algorithms')
75
                                ->info('A list of supported content encryption algorithms.')
76
                                ->useAttributeAsKey('name')
77
                                ->isRequired()
78
                                ->prototype('scalar')->end()
79
                            ->end()
80
                            ->arrayNode('compression_methods')
81
                                ->info('A list of supported compression methods.')
82
                                ->useAttributeAsKey('name')
83
                                ->defaultValue(['DEF'])
84
                                ->prototype('scalar')->end()
85
                            ->end()
86
                        ->end()
87
                    ->end()
88
                ->end()
89
            ->end();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function prepend(ContainerBuilder $container, array $config): ?array
96
    {
97
        return null;
98
    }
99
}
100