Completed
Push — master ( 755e9e...9e5cc9 )
by Florent
01:58
created

DecrypterSource   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A createService() 0 17 2
A addConfigurationSection() 0 17 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\Definition;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
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 addConfigurationSection(ArrayNodeDefinition $node)
54
    {
55
        $node->children()
56
            ->arrayNode('decrypters')
57
            ->useAttributeAsKey('name')
58
            ->prototype('array')
59
            ->children()
60
            ->arrayNode('key_encryption_algorithms')->isRequired()->prototype('scalar')->end()->end()
61
            ->arrayNode('content_encryption_algorithms')->isRequired()->prototype('scalar')->end()->end()
62
            ->arrayNode('compression_methods')->defaultValue(['DEF'])->prototype('scalar')->end()->end()
63
            ->scalarNode('logger')->defaultNull()->end()
64
            ->booleanNode('create_decrypter')->defaultTrue()->end()
65
            ->end()
66
            ->end()
67
            ->end()
68
            ->end();
69
    }
70
}
71