Failed Conditions
Push — master ( 426864...d9377e )
by Florent
02:04
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 0
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\JoseFramework\DependencyInjection;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\SourceInterface;
17
use Jose\Component\Core\Converter\StandardJsonConverter;
18
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
19
use Symfony\Component\Config\Definition\ConfigurationInterface;
20
21
/**
22
 * Class Configuration.
23
 */
24
final class Configuration implements ConfigurationInterface
25
{
26
    /**
27
     * @var SourceInterface[]
28
     */
29
    private $serviceSources;
30
31
    /**
32
     * @var string
33
     */
34
    private $alias;
35
36
    /**
37
     * Configuration constructor.
38
     *
39
     * @param string            $alias
40
     * @param SourceInterface[] $serviceSources
41
     */
42
    public function __construct(string $alias, array $serviceSources)
43
    {
44
        $this->alias = $alias;
45
        $this->serviceSources = $serviceSources;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getConfigTreeBuilder()
52
    {
53
        $treeBuilder = new TreeBuilder();
54
        $rootNode = $treeBuilder->root($this->alias);
55
56
        foreach ($this->serviceSources as $serviceSource) {
57
            $serviceSource->getNodeDefinition($rootNode);
58
        }
59
60
        $rootNode
61
            ->children()
62
                ->scalarNode('json_converter')
63
                    ->defaultValue(StandardJsonConverter::class)
64
                    ->info('Converter used to encode and decode JSON objects (JWT payloads, keys, key sets...). If set to false, a service that implements JsonConverterInterface must be set.')
65
                ->end()
66
            ->end();
67
68
        return $treeBuilder;
69
    }
70
}
71