Completed
Push — master ( 70c29b...7d604a )
by Tomasz
06:29
created

Configuration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Gendoria\CommandQueueRabbitMqDriverBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * This is the class that validates and merges configuration from your app/config files.
10
 *
11
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12
 */
13
class Configuration implements ConfigurationInterface
14
{
15
    /**
16
     * Master configuration key.
17
     *
18
     * @var string
19
     */
20
    private $alias;
21
22
    /**
23
     * Class constructor.
24
     *
25
     * @param string $alias
26
     */
27 2
    public function __construct($alias)
28
    {
29 2
        $this->alias = $alias;
30 2
    }
31
32
    /**
33
     * Get config tree builder instance.
34
     *
35
     * {@inheritdoc}
36
     *
37
     * @return TreeBuilder
38
     */
39 2
    public function getConfigTreeBuilder()
40 1
    {
41 2
        $treeBuilder = new TreeBuilder();
42 2
        $rootNode = $treeBuilder->root($this->alias);
43 2
        $rootNode->children()
44 2
            ->scalarNode('serializer')
45 2
                ->cannotBeEmpty()
46 2
                ->isRequired()
47 2
                ->validate()
48 2
                    ->ifTrue(function($v) {
49 2
                        return strpos($v, '@') !== 0;
50 2
                    })
51 2
                    ->thenInvalid('Serializer has to be in form "@service.id"')
52 2
                ->end()
53 2
            ->end()
54 2
            ->arrayNode('drivers')
55 2
                ->prototype('array')
56 2
                    ->children()
57 2
                        ->scalarNode('rabbitmq_connection')
58 2
                            ->cannotBeEmpty()
59 2
                            ->isRequired()
60 2
                        ->end()
61 2
                        ->scalarNode('exchange_name')
62 2
                            ->cannotBeEmpty()
63 2
                            ->isRequired()
64 2
                        ->end()
65 2
                        ->scalarNode('consumer_name')
66 2
                            ->cannotBeEmpty()
67 2
                            ->isRequired()
68 2
                        ->end()
69 2
                        ->scalarNode('consumer_queue_name')
70 2
                            ->cannotBeEmpty()
71 2
                            ->isRequired()
72 2
                        ->end()
73 2
                        ->scalarNode('producer_name')
74 2
                            ->cannotBeEmpty()
75 2
                            ->isRequired()
76 2
                        ->end()
77 2
                    ->end()
78 2
                ->end()
79 2
            ->end()
80 2
        ->end();
81
82
        // Here you should define the parameters that are allowed to
83
        // configure your bundle. See the documentation linked above for
84
        // more information on that topic.
85
86 2
        return $treeBuilder;
87
    }
88
}
89