Failed Conditions
Push — v7 ( 69552d...3dace9 )
by Florent
03:23
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 26
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
                ->arrayNode('jku_factory')
67
                    ->canBeEnabled()
68
                    ->children()
69
                        ->scalarNode('client')
70
                            ->info('HTTP Client used to retrieve key sets.')
71
                            ->isRequired()
72
                            ->defaultNull()
73
                        ->end()
74
                        ->scalarNode('request_factory')
75
                            ->defaultValue('Http\Message\MessageFactory\GuzzleMessageFactory')
76
                        ->end()
77
                    ->end()
78
                ->end()
79
            ->end();
80
81
        return $treeBuilder;
82
    }
83
}
84