DecrypterSource::getNodeDefinition()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 30
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
        ]);
45
        $definition->setPublic($config['is_public']);
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
                            ->booleanNode('is_public')
62
                                ->info('If true, the service will be public, else private.')
63
                                ->defaultTrue()
64
                            ->end()
65
                            ->arrayNode('key_encryption_algorithms')
66
                                ->useAttributeAsKey('name')
67
                                ->isRequired()
68
                                ->prototype('scalar')->end()
69
                            ->end()
70
                            ->arrayNode('content_encryption_algorithms')
71
                                ->useAttributeAsKey('name')
72
                                ->isRequired()
73
                                ->prototype('scalar')->end()
74
                            ->end()
75
                            ->arrayNode('compression_methods')
76
                                ->useAttributeAsKey('name')
77
                                ->defaultValue(['DEF'])
78
                                ->prototype('scalar')->end()
79
                            ->end()
80
                        ->end()
81
                    ->end()
82
                ->end()
83
            ->end();
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function prepend(ContainerBuilder $container, array $config)
90
    {
91
    }
92
}
93