Passed
Pull Request — release/4.x (#44)
by Erik
07:43 queued 03:55
created

Configuration   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 64
dl 0
loc 79
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 74 1
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\UrlBundle\DependencyInjection;
8
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
use Symfony\Component\Config\Definition\ConfigurationInterface;
11
12
/**
13
 * Configuration schema for the url bundle
14
 */
15
class Configuration implements ConfigurationInterface
16
{
17
    /**
18
     * {@inheritDoc}
19
     */
20
    public function getConfigTreeBuilder()
21
    {
22
        $treeBuilder = new TreeBuilder();
23
        $rootNode = $treeBuilder->root('zicht_url');
24
25
        $isBool = function ($v) {
26
            return is_bool($v);
27
        };
28
        $convertToEnabledKey = function ($v) {
29
            return ['enabled' => $v];
30
        };
31
32
        $rootNode
33
            ->children()
34
                ->booleanNode('strict_public_url')->defaultValue(true)->end()
35
                ->arrayNode('static_ref')
36
                    ->useAttributeAsKey('name')
37
                    ->prototype('scalar')->end()
38
                ->end()
39
                ->arrayNode('aliasing')
40
                    ->beforeNormalization()
41
                        ->ifTrue($isBool)
42
                        ->then($convertToEnabledKey)
43
                    ->end()
44
                    ->addDefaultsIfNotSet()
45
                    ->children()
46
                        ->booleanNode('enabled')->defaultValue(false)->end()
47
                        ->booleanNode('enable_params')->defaultValue(false)->end()
48
                        ->arrayNode('exclude_patterns')->prototype('scalar')->end()->end()
49
                        ->arrayNode('automatic_entities')->prototype('scalar')->end()->end()
50
                    ->end()
51
                ->end()
52
                ->variableNode('logging')->end()
53
                ->booleanNode('admin')->defaultValue(false)->end()
54
                ->arrayNode('db_static_ref')
55
                    ->beforeNormalization()
56
                        ->ifTrue($isBool)
57
                        ->then($convertToEnabledKey)
58
                    ->end()
59
                    ->addDefaultsIfNotSet()
60
                    ->children()
61
                        ->booleanNode('enabled')->defaultValue(false)->end()
62
                        ->scalarNode('fallback_locale')->defaultValue(null)->end()
63
                    ->end()
64
                ->end()
65
                ->arrayNode('caching')
66
                    ->beforeNormalization()
67
                        ->ifTrue($isBool)
68
                        ->then($convertToEnabledKey)
69
                    ->end()
70
                    ->addDefaultsIfNotSet()
71
                    ->children()
72
                        ->booleanNode('enabled')->defaultValue(false)->end()
73
                        ->arrayNode('entities')->prototype('scalar')->end()->end()
74
                    ->end()
75
                ->end()
76
                ->variableNode('html_attributes')
77
                    ->treatNullLike([])
78
                    ->defaultValue(
79
                        [
80
                            'a' => ['href', 'data-href'],
81
                            'area' => ['href', 'data-href'],
82
                            'iframe' => ['src'],
83
                            'form' => ['action'],
84
                            'meta' => ['content'],
85
                            'link' => ['href']
86
                        ]
87
                    )
88
                ->end()
89
                // usage if this setting is deprecated and no longer has any effect.
90
                ->variableNode('unalias_subscriber')->end()
91
            ->end();
92
93
        return $treeBuilder;
94
    }
95
}
96