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