Completed
Push — master ( a72ead...580ca1 )
by Danny
02:49
created

Configuration::addRpcServer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 1
crap 1
1
<?php
2
3
namespace MyOnlineStore\Bundle\RabbitMqManagerBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * This bundle uses the rabbit mq bundle's configuration
11
 */
12
class Configuration implements ConfigurationInterface
13
{
14
    /**
15
     * @inheritdoc
16
     */
17 2
    public function getConfigTreeBuilder()
18
    {
19 2
        $tree = new TreeBuilder();
20
21 2
        $rootNode = $tree->root('rabbit_mq_manager');
22
23
        $rootNode
24 2
            ->children()
25 2
                ->scalarNode('path')->defaultValue('%kernel.root_dir%/../var/supervisor/%kernel.name%')->end()
26 2
            ->end();
27 2
        $this->addCommands($rootNode);
28 2
        $this->addConsumer($rootNode);
29 2
        $this->addRpcServer($rootNode);
30
31 2
        return $tree;
32
    }
33
34
    /**
35
     * Add commands configuration
36
     *
37
     * @param ArrayNodeDefinition $node
38
     */
39 2
    protected function addCommands(ArrayNodeDefinition $node)
40 1
    {
41
        $node
42 2
            ->fixXmlConfig('command')
43 2
            ->children()
44 2
                ->arrayNode('commands')
45 2
                ->addDefaultsIfNotSet()
46 2
                    ->children()
47 2
                        ->scalarNode('cli_consumer_invoker')->defaultValue('rabbitmq-manager:consumer')->end()
48 2
                        ->scalarNode('consumers')->defaultValue('rabbitmq:consumer')->end()
49 2
                        ->scalarNode('multiple_consumers')->defaultValue('rabbitmq:multiple-consumer')->end()
50 2
                        ->scalarNode('rpc_servers')->defaultValue('rabbitmq:rpc-server')->end()
51 2
                    ->end()
52 2
                ->end()
53 2
            ->end()
54
        ;
55 2
    }
56
57
    /**
58
     * Add general and individual consumer configuration
59
     *
60
     * @param ArrayNodeDefinition $node
61
     */
62 2
    protected function addConsumer(ArrayNodeDefinition $node)
63
    {
64
        $consumerChildren = $node
65 2
            ->children()
66 2
                ->arrayNode('consumers')
67 2
                ->addDefaultsIfNotSet()
68 2
                    ->children();
69
70
        $general = $consumerChildren
71 2
                        ->arrayNode('general');
72 2
        $this->addGeneralConsumerConfiguration($general);
73
74
        $individualPrototype = $consumerChildren
75 2
                        ->arrayNode('individual')
76 2
                            ->useAttributeAsKey('consumers')
77 2
                            ->prototype('array');
78 2
        $this->addGeneralConsumerConfiguration($individualPrototype);
79 2
    }
80
81
    /**
82
     * Add general and individual consumer configuration
83
     *
84
     * @param ArrayNodeDefinition $node
85
     */
86 2
    protected function addRpcServer(ArrayNodeDefinition $node)
87
    {
88
        $consumerChildren = $node
89 2
            ->children()
90 2
            ->arrayNode('rpc_servers')
91 2
            ->addDefaultsIfNotSet()
92 2
            ->children();
93
94
        $general = $consumerChildren
95 2
            ->arrayNode('general');
96 2
        $this->addGeneralConsumerConfiguration($general);
97
98
        $individualPrototype = $consumerChildren
99 2
            ->arrayNode('individual')
100 2
            ->useAttributeAsKey('rpc_servers')
101 2
            ->prototype('array');
102 2
        $this->addGeneralConsumerConfiguration($individualPrototype);
103 2
    }
104
105
    /**
106
     * Add consumer configuration
107
     *
108
     * @param ArrayNodeDefinition $node
109
     */
110 2
    protected function addGeneralConsumerConfiguration(ArrayNodeDefinition $node)
111
    {
112
        $node
113 2
        ->normalizeKeys(false)
114 2
        ->addDefaultsIfNotSet()
115 2
            ->children()
116 2
                ->enumNode('processor')
117 2
                    ->values(['bundle', 'cli-consumer'])
118 2
                    ->defaultValue('bundle')
119 2
                ->end()
120 2
                ->integerNode('messages')
121 2
                    ->min(0)
122 2
                    ->defaultValue(0)
123 2
                ->end()
124 2
                ->booleanNode('compression')
125 2
                    ->defaultTrue()
126 2
                ->end()
127 2
                ->arrayNode('worker')
128 2
                ->addDefaultsIfNotSet()
129 2
                    ->children()
130 2
                        ->integerNode('count')
131 2
                            ->min(1)
132 2
                            ->defaultValue(1)
133 2
                        ->end()
134 2
                        ->integerNode('startsecs')
135 2
                            ->min(0)
136 2
                            ->defaultValue(0)
137 2
                        ->end()
138 2
                        ->booleanNode('autorestart')
139 2
                            ->defaultTrue()
140 2
                        ->end()
141 2
                        ->enumNode('stopsignal')
142 2
                            ->values(['TERM', 'INT', 'KILL'])
143 2
                            ->defaultValue('INT')
144 2
                        ->end()
145 2
                        ->booleanNode('stopasgroup')
146 2
                            ->defaultTrue()
147 2
                        ->end()
148 2
                        ->integerNode('stopwaitsecs')
149 2
                            ->min(0)
150 2
                            ->defaultValue(60)
151 2
                        ->end()
152 2
                    ->end()
153 2
                ->end()
154 2
            ->end()
155
        ;
156 2
    }
157
}
158