Completed
Push — master ( ce82a2...2c4ca0 )
by Florent
02:09
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 34
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

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