Configuration   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 25
c 2
b 0
f 0
dl 0
loc 42
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 29 1
1
<?php
2
3
/*
4
 * This file is part of the syntaxhighligter-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
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 WBW\Bundle\SyntaxHighlighterBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
use WBW\Bundle\CoreBundle\DependencyInjection\ConfigurationHelper;
17
18
/**
19
 * Configuration.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\SyntaxHighlighterBundle\DependencyInjection
23
 */
24
class Configuration implements ConfigurationInterface {
25
26
    /**
27
     * {@inheritDoc}
28
     *
29
     * wbw_syntaxhighlighter:
30
     *      twig:  false
31
     *      theme: Django
32
     *      brushes:
33
     *          - "Php"
34
     *          - "Css"
35
     *          - "JScript"
36
     */
37
    public function getConfigTreeBuilder() {
38
39
        $assets  = ConfigurationHelper::loadYamlConfig(__DIR__, "assets");
40
        $brushes = $assets["assets"]["wbw.syntaxhighlighter.asset.syntaxhighlighter"]["brushes"];
41
        $themes  = $assets["assets"]["wbw.syntaxhighlighter.asset.syntaxhighlighter"]["themes"];
42
43
        $treeBuilder = new TreeBuilder(WBWSyntaxHighlighterExtension::EXTENSION_ALIAS);
44
45
        $rootNode = ConfigurationHelper::getRootNode($treeBuilder, WBWSyntaxHighlighterExtension::EXTENSION_ALIAS);
46
        $rootNode
47
            ->children()
48
                ->booleanNode("twig")->defaultTrue()->info("Load Twig extensions")->end()
49
                ->variableNode("theme")->defaultValue("Default")->info("SyntaxHightlighter theme")
50
                    ->validate()
51
                        ->ifNotInArray($themes)
52
                        ->thenInvalid("The SyntaxHighlighter theme %s is not supported. Please choose one of " . json_encode($themes))
53
                    ->end()
54
                ->end()
55
                ->arrayNode("brushes")->info("Use SyntaxHightlighter brushes")
56
                    ->prototype("scalar")
57
                        ->validate()
58
                            ->ifNotInArray($brushes)
59
                            ->thenInvalid("The SyntaxHighlighter brush %s is not supported. Please choose one of " . json_encode($brushes))
60
                        ->end()
61
                    ->end()
62
                ->end()
63
            ->end();
64
65
        return $treeBuilder;
66
    }
67
}
68