Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 45
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 45
rs 8.8571
cc 3
eloc 40
nc 1
nop 0
1
<?php
2
3
namespace CedricZiel\ShariffBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * This is the class that validates and merges configuration from your app/config files
10
 *
11
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12
 */
13
class Configuration implements ConfigurationInterface
14
{
15
    /**
16
     * {@inheritDoc}
17
     */
18
    public function getConfigTreeBuilder()
19
    {
20
        $treeBuilder = new TreeBuilder();
21
        $rootNode = $treeBuilder->root('cedricziel_shariff');
22
23
        $rootNode
24
            ->children()
25
                ->scalarNode('domain')->isRequired()->end()
26
                ->scalarNode('force_protocol')->defaultNull()->end()
27
                ->arrayNode('cache')
28
                    ->addDefaultsIfNotSet()
29
                    ->children()
30
                        ->scalarNode('cacheDir')->defaultNull()->end()
31
                        ->scalarNode('ttl')->defaultValue(1800)->end()
32
                        ->scalarNode('adapter')->defaultNull()->end()
33
                        ->arrayNode('adapterOptions')
34
                            ->useAttributeAsKey('name')
35
                            ->prototype('variable')
36
                                ->validate()
37
                                    ->ifTrue(function($v) { return !is_array($v) && !is_null($v); })
38
                                    ->thenInvalid('The services config %s must be either null or an array.')
39
                                ->end()
40
                            ->end()
41
                        ->end()
42
                    ->end()
43
                ->end()
44
                ->arrayNode('services')
45
                    ->useAttributeAsKey('name')
46
                    ->prototype('variable')
47
                        ->validate()
48
                            ->ifTrue(function($v) { return !is_array($v) && !is_null($v); })
49
                            ->thenInvalid('The services config %s must be either null or an array.')
50
                        ->end()
51
                    ->end()
52
                ->end()
53
                ->arrayNode('client')
54
                    ->useAttributeAsKey('name')
55
                    ->prototype('variable')
56
                    ->end()
57
                ->end()
58
            ->end()
59
        ;
60
61
        return $treeBuilder;
62
    }
63
}
64