Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 25

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 29
rs 8.8571
cc 1
eloc 25
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Bundle\ClientBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * XApi client bundle configuration.
19
 *
20
 * @author Christian Flothmann <[email protected]>
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = new TreeBuilder();
30
        $rootNode = $treeBuilder->root('xabbuh_xapi_client');
31
32
        $rootNode
33
            ->fixXmlConfig('client')
34
            ->children()
35
                ->arrayNode('clients')
36
                    ->useAttributeAsKey('name')
37
                    ->prototype('array')
38
                        ->children()
39
                            ->scalarNode('base_url')->isRequired()->end()
40
                            ->scalarNode('username')->end()
41
                            ->scalarNode('password')->end()
42
                            ->scalarNode('version')
43
                                ->defaultValue('1.0.1')
44
                                ->validate()
45
                                    ->ifNotInArray(array('1.0.0', '1.0.1'))
46
                                    ->thenInvalid('Version must be on of 1.0.0, 1.0.1')
47
                                ->end()
48
                            ->end()
49
                        ->end()
50
                    ->end()
51
                ->end()
52
            ->end();
53
54
        return $treeBuilder;
55
    }
56
}
57