Completed
Push — master ( 8e9c64...20353b )
by Florent
04:07
created

Configuration::addKeySection()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 50
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 4 Features 1
Metric Value
c 8
b 4
f 1
dl 0
loc 50
rs 8.8571
cc 4
eloc 44
nc 1
nop 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2015 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;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
18
19
final class Configuration implements ConfigurationInterface
20
{
21
    private $alias;
22
23
    /**
24
     * @param string $alias
25
     */
26
    public function __construct($alias)
27
    {
28
        $this->alias = $alias;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getConfigTreeBuilder()
35
    {
36
        $treeBuilder = new TreeBuilder();
37
        $rootNode = $treeBuilder->root($this->alias);
38
39
        $this->addStorageSection($rootNode);
40
        $rootNode
41
            ->children()
42
                ->scalarNode('server_name')->cannotBeEmpty()->defaultValue('OAuth2 Server')->end()
43
                ->arrayNode('algorithms')->prototype('scalar')->end()->treatNullLike([])->end()
44
                ->arrayNode('compression_methods')->prototype('scalar')->end()->treatNullLike([])->end()
45
            ->end();
46
47
        return $treeBuilder;
48
    }
49
50
    /**
51
     * @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node
52
     */
53
    private function addStorageSection(ArrayNodeDefinition $node)
54
    {
55
        $node
56
            ->children()
57
                ->arrayNode('jot')
58
                    ->children()
59
                        ->booleanNode('enabled')->defaultFalse()->end()
60
                        ->scalarNode('manager')->defaultValue('jose.jot_manager.default')->cannotBeEmpty()->end()
61
                        ->scalarNode('class')->defaultNull()->end()
62
                    ->end()
63
                ->end()
64
            ->end();
65
    }
66
}
67