Completed
Push — master ( b6ba4a...f73367 )
by Florent
02:26
created

DecrypterSource::getNodeDefinition()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 34
rs 8.8571
cc 1
eloc 32
nc 1
nop 1
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 DecrypterSource implements SourceInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function getName()
25
    {
26
        return 'decrypters';
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function createService($name, array $config, ContainerBuilder $container)
33
    {
34
        $service_id = sprintf('jose.decrypter.%s', $name);
35
        $definition = new Definition('Jose\Decrypter');
36
        $definition->setFactory([
37
            new Reference('jose.factory.service'),
38
            'createDecrypter',
39
        ]);
40
        $definition->setArguments([
41
            $config['key_encryption_algorithms'],
42
            $config['content_encryption_algorithms'],
43
            $config['compression_methods'],
44
            null === $config['logger'] ? null : new Reference($config['logger']),
45
        ]);
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
                            ->arrayNode('key_encryption_algorithms')
62
                                ->useAttributeAsKey('name')
63
                                ->isRequired()
64
                                ->prototype('scalar')->end()
65
                            ->end()
66
                            ->arrayNode('content_encryption_algorithms')
67
                                ->useAttributeAsKey('name')
68
                                ->isRequired()
69
                                ->prototype('scalar')->end()
70
                            ->end()
71
                            ->arrayNode('compression_methods')
72
                                ->useAttributeAsKey('name')
73
                                ->defaultValue(['DEF'])
74
                                ->prototype('scalar')->end()
75
                            ->end()
76
                            ->scalarNode('logger')
77
                                ->defaultNull()
78
                            ->end()
79
                            ->booleanNode('create_decrypter')
80
                                ->defaultTrue()
81
                            ->end()
82
                        ->end()
83
                    ->end()
84
                ->end()
85
            ->end();
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function prepend(ContainerBuilder $container, array $config)
92
    {
93
    }
94
}
95