Completed
Push — feature/rewrite ( f6b662...4d09af )
by Alexandre
01:59
created

Configuration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Black\Bundle\PageBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * Class Configuration
11
 */
12
class Configuration implements ConfigurationInterface
13
{
14
    private $alias;
15
16
    /**
17
     * @param string $alias
18
     */
19
    public function __construct($alias)
20
    {
21
        $this->alias = $alias;
22
    }
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = new TreeBuilder();
30
        $rootNode    = $treeBuilder->root($this->alias);
31
32
        $supportedDrivers = ['mongodb', 'orm'];
33
34
        $rootNode
35
            ->children()
36
37
                ->scalarNode('db_driver')
38
                    ->validate()
39
                        ->ifNotInArray($supportedDrivers)
40
                        ->thenInvalid('The database driver %s is not supported. Please choose one of ' . json_encode($supportedDrivers))
41
                    ->end()
42
                    ->isRequired()
43
                    ->cannotBeOverwritten()
44
                    ->cannotBeEmpty()
45
                ->end()
46
47
                ->scalarNode('page_class')->isRequired()->cannotBeEmpty()->end()
48
            ->end();
49
50
        return $treeBuilder;
51
    }
52
}
53