Completed
Push — master ( b10e46...20af00 )
by Christian
263:11
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[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 Core23\SitemapBundle\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
final class Configuration implements ConfigurationInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function getConfigTreeBuilder()
24
    {
25
        $treeBuilder = new TreeBuilder();
26
27
        /** @var ArrayNodeDefinition $node */
28
        $node = $treeBuilder->root('core23_sitemap');
29
30
        $this->addStaticUrlsSection($node);
31
        $this->addCacheSection($node);
32
33
        return $treeBuilder;
34
    }
35
36
    /**
37
     * @param ArrayNodeDefinition $node
38
     */
39
    private function addCacheSection(ArrayNodeDefinition $node): void
40
    {
41
        $node
42
            ->children()
43
                ->arrayNode('cache')
44
                    ->addDefaultsIfNotSet()
45
                    ->children()
46
                        ->scalarNode('service')->defaultNull()->end()
47
                    ->end()
48
                ->end()
49
            ->end()
50
        ;
51
    }
52
53
    /**
54
     * @param ArrayNodeDefinition $node
55
     */
56
    private function addStaticUrlsSection(ArrayNodeDefinition $node): void
57
    {
58
        $node
59
            ->children()
60
                ->arrayNode('static')
61
                    ->defaultValue([])
62
                    ->prototype('array')
63
                        ->children()
64
                             ->scalarNode('url')->end()
65
                             ->integerNode('priority')->defaultNull()->end()
66
                             ->scalarNode('changefreq')->defaultNull()->end()
67
                        ->end()
68
                    ->end()
69
                ->end()
70
            ->end()
71
        ;
72
    }
73
}
74