Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 47
c 0
b 0
f 0
rs 9.0303
cc 1
eloc 39
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of HeriJobQueueBundle.
5
 *
6
 * (c) Alexandre Mogère
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Heri\Bundle\JobQueueBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * This is the class that validates and merges configuration from your app/config files.
19
 *
20
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = new TreeBuilder();
30
        $rootNode = $treeBuilder->root('heri_job_queue');
31
32
        $rootNode
33
            ->addDefaultsIfNotSet()
34
            ->children()
35
36
                ->scalarNode('adapter')
37
                    ->defaultValue('doctrine')
38
                    ->validate()
39
                    ->ifNotInArray(['doctrine', 'amqp'])
40
                        ->thenInvalid('Invalid adapter "%s"')
41
                    ->end()
42
                ->end()
43
                ->booleanNode('enabled')
44
                    ->defaultTrue()
45
                ->end()
46
                ->integerNode('max_messages')
47
                    ->defaultValue(1)
48
                    ->min(1)
49
                ->end()
50
                ->integerNode('process_timeout')
51
                    ->defaultNull()
52
                    ->min(1)
53
                ->end()
54
                ->arrayNode('queues')
55
                    ->prototype('scalar')
56
                    ->end()
57
                ->end()
58
59
                ->arrayNode('amqp_connection')
60
                    ->addDefaultsIfNotSet()
61
                    ->children()
62
                        ->scalarNode('host')->defaultValue('localhost')->end()
63
                        ->scalarNode('port')->defaultValue('5672')->end()
64
                        ->scalarNode('user')->defaultValue('guest')->end()
65
                        ->scalarNode('password')->defaultValue('guest')->end()
66
                    ->end()
67
                ->end()
68
69
            ->end()
70
        ;
71
72
        return $treeBuilder;
73
    }
74
}
75