Completed
Pull Request — 2.x (#161)
by Christian
05:03
created

Configuration::addHTTPlugSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 1
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[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 Sonata\SeoBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
/**
19
 * This is the class that validates and merges configuration from your app/config files.
20
 */
21
class Configuration implements ConfigurationInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getConfigTreeBuilder()
27
    {
28
        $treeBuilder = new TreeBuilder();
29
30
        $node = $treeBuilder->root('sonata_seo');
31
32
        $node
33
            ->children()
34
                ->scalarNode('encoding')->defaultValue('UTF-8')->end()
35
                ->arrayNode('page')
36
                    ->addDefaultsIfNotSet()
37
                    ->children()
38
                        ->scalarNode('default')->defaultValue('sonata.seo.page.default')->end()
39
                        ->arrayNode('head')
40
                            ->normalizeKeys(false)
41
                            ->useAttributeAsKey('attribute')
42
                            ->prototype('scalar')->end()
43
                        ->end()
44
                        ->arrayNode('metas')
45
                            ->normalizeKeys(false)
46
                            ->useAttributeAsKey('element')
47
                            ->prototype('array')
48
                                ->normalizeKeys(false)
49
                                ->useAttributeAsKey('name')
50
                                ->prototype('scalar')->end()
51
                            ->end()
52
                        ->end()
53
                        ->scalarNode('separator')->defaultValue(' - ')->end()
54
                        // NEXT_MAJOR: Make this field required
55
                        ->scalarNode('title')->defaultValue('Project name')->end()
56
                    ->end()
57
                ->end()
58
                ->arrayNode('sitemap')
59
                    ->addDefaultsIfNotSet()
60
                    ->children()
61
                        ->arrayNode('doctrine_orm')
62
                            ->prototype('variable')->end()
63
                        ->end()
64
                        ->arrayNode('services')
65
                            ->prototype('variable')->end()
66
                        ->end()
67
                    ->end()
68
                ->end()
69
            ->end()
70
        ;
71
72
        $this->addHTTPlugSection($node);
73
74
        return $treeBuilder;
75
    }
76
77
    /**
78
     * @param ArrayNodeDefinition $node
79
     */
80
    private function addHTTPlugSection(ArrayNodeDefinition $node)
81
    {
82
        $node
83
            ->children()
84
                ->arrayNode('http')
85
                    ->addDefaultsIfNotSet()
86
                    ->children()
87
                        ->scalarNode('client')
88
                            ->defaultValue('httplug.client.default')
89
                            ->info('Alias of the HTTPlug client.')
90
                        ->end()
91
                        ->scalarNode('message_factory')
92
                            ->defaultValue('httplug.message_factory.default')
93
                            ->info('Alias of the HTTPlug message factory.')
94
                        ->end()
95
                    ->end()
96
                ->end()
97
            ->end();
98
    }
99
}
100