Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the SimpleSerializerBundle package.
5
 *
6
 * Copyright (c) 2012 Farheap Solutions (http://www.farheap.com)
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 Opensoft\Bundle\SimpleSerializerBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
class Configuration implements ConfigurationInterface
19
{
20
    /***
21
     * @var bool
22
     */
23
    private $debug;
24
25
    /**
26
     * @param bool $debug
27
     */
28
    public function __construct($debug = false)
29
    {
30
        $this->debug = $debug;
31
    }
32
33
    public function getConfigTreeBuilder()
34
    {
35
        $tb = new TreeBuilder();
36
37
        $root = $tb
38
            ->root('opensoft_simple_serializer', 'array')
39
                ->children()
40
        ;
41
        $this->addMetadataSection($root);
42
43
        return $tb;
44
    }
45
46
    private function addMetadataSection(NodeBuilder $builder)
47
    {
48
        $builder
49
            ->arrayNode('metadata')
50
                ->addDefaultsIfNotSet()
51
                ->fixXmlConfig('directory', 'directories')
52
                ->children()
53
                    ->scalarNode('cache')->defaultValue('file')->end()
54
                    ->booleanNode('debug')->defaultValue($this->debug)->end()
55
                    ->arrayNode('file_cache')
56
                        ->addDefaultsIfNotSet()
57
                        ->children()
58
                            ->scalarNode('dir')->defaultValue('%kernel.cache_dir%/simple-serializer')->end()
59
                        ->end()
60
                    ->end()
61
                    ->booleanNode('auto_detection')->defaultTrue()->end()
62
                    ->arrayNode('directories')
63
                        ->prototype('array')
64
                            ->children()
65
                                ->scalarNode('path')->isRequired()->end()
66
                                ->scalarNode('namespace_prefix')->defaultValue('')->end()
67
                            ->end()
68
                        ->end()
69
                    ->end()
70
                ->end()
71
            ->end()
72
        ;
73
    }
74
}
75