1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Dtc\QueueBundle\Model\PriorityJobManager; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
8
|
|
|
|
9
|
|
|
class Configuration implements ConfigurationInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Generates the configuration tree. |
13
|
|
|
* |
14
|
|
|
* @return TreeBuilder |
15
|
|
|
*/ |
16
|
3 |
|
public function getConfigTreeBuilder() |
17
|
|
|
{ |
18
|
3 |
|
$treeBuilder = new TreeBuilder(); |
19
|
3 |
|
$rootNode = $treeBuilder->root('dtc_queue'); |
20
|
|
|
|
21
|
|
|
$rootNode |
22
|
3 |
|
->children() |
23
|
3 |
|
->scalarNode('document_manager') |
24
|
3 |
|
->defaultValue('default') |
25
|
3 |
|
->cannotBeEmpty() |
26
|
3 |
|
->end() |
27
|
3 |
|
->scalarNode('entity_manager') |
28
|
3 |
|
->defaultValue('default') |
29
|
3 |
|
->cannotBeEmpty() |
30
|
3 |
|
->end() |
31
|
3 |
|
->scalarNode('default_manager') |
32
|
3 |
|
->defaultValue('mongodb') |
33
|
3 |
|
->cannotBeEmpty() |
34
|
3 |
|
->end() |
35
|
3 |
|
->scalarNode('run_manager') |
36
|
3 |
|
->end() |
37
|
3 |
|
->scalarNode('document_am') |
38
|
3 |
|
->end() |
39
|
3 |
|
->scalarNode('class_job') |
40
|
3 |
|
->end() |
41
|
3 |
|
->scalarNode('class_job_archive') |
42
|
3 |
|
->end() |
43
|
3 |
|
->scalarNode('class_job_timing') |
44
|
3 |
|
->end() |
45
|
3 |
|
->scalarNode('class_run') |
46
|
3 |
|
->end() |
47
|
3 |
|
->scalarNode('class_run_archive') |
48
|
3 |
|
->end() |
49
|
3 |
|
->booleanNode('record_timings')->defaultFalse() |
50
|
3 |
|
->end() |
51
|
3 |
|
->integerNode('priority_max')->defaultValue(255) |
52
|
3 |
|
->end() |
53
|
3 |
|
->enumNode('priority_direction')->values([PriorityJobManager::PRIORITY_ASC, PriorityJobManager::PRIORITY_DESC])->defaultValue(PriorityJobManager::PRIORITY_DESC)->end() |
54
|
3 |
|
->arrayNode('beanstalkd') |
55
|
3 |
|
->children() |
56
|
3 |
|
->scalarNode('host')->end() |
57
|
3 |
|
->scalarNode('tube')->end() |
58
|
3 |
|
->end() |
59
|
3 |
|
->end() |
60
|
3 |
|
->arrayNode('rabbit_mq') |
61
|
3 |
|
->children() |
62
|
3 |
|
->scalarNode('host')->end() |
63
|
3 |
|
->scalarNode('port')->end() |
64
|
3 |
|
->scalarNode('user')->end() |
65
|
3 |
|
->scalarNode('password')->end() |
66
|
3 |
|
->scalarNode('vhost')->defaultValue('/')->end() |
67
|
3 |
|
->booleanNode('ssl')->defaultFalse()->end() |
68
|
3 |
|
->arrayNode('options') |
69
|
3 |
|
->children() |
70
|
3 |
|
->scalarNode('insist')->end() |
71
|
3 |
|
->scalarNode('login_method')->end() |
72
|
3 |
|
->scalarNode('login_response')->end() |
73
|
3 |
|
->scalarNode('locale')->end() |
74
|
3 |
|
->floatNode('connection_timeout')->end() |
75
|
3 |
|
->floatNode('read_write_timeout')->end() |
76
|
3 |
|
->booleanNode('keepalive')->end() |
77
|
3 |
|
->integerNode('heartbeat')->end() |
78
|
3 |
|
->end() |
79
|
3 |
|
->end() |
80
|
3 |
|
->arrayNode('ssl_options') |
81
|
3 |
|
->prototype('variable')->end() |
82
|
3 |
|
->validate() |
83
|
3 |
|
->ifTrue(function ($node) { |
84
|
1 |
|
if (!is_array($node)) { |
85
|
|
|
return true; |
86
|
|
|
} |
87
|
1 |
|
foreach ($node as $key => $value) { |
88
|
1 |
|
if (is_array($value)) { |
89
|
1 |
|
if ('peer_fingerprint' !== $key) { |
90
|
1 |
|
return true; |
91
|
|
|
} else { |
92
|
1 |
|
foreach ($value as $key1 => $value1) { |
93
|
1 |
|
if (!is_string($key1) || !is_string($value1)) { |
94
|
1 |
|
return true; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
return false; |
102
|
3 |
|
}) |
103
|
3 |
|
->thenInvalid('Must be key-value pairs') |
104
|
3 |
|
->end() |
105
|
3 |
|
->end() |
106
|
3 |
|
->arrayNode('queue_args') |
107
|
3 |
|
->addDefaultsIfNotSet() |
108
|
3 |
|
->children() |
109
|
3 |
|
->scalarNode('queue')->defaultValue('dtc_queue')->end() |
110
|
3 |
|
->booleanNode('passive')->defaultFalse()->end() |
111
|
3 |
|
->booleanNode('durable')->defaultTrue()->end() |
112
|
3 |
|
->booleanNode('exclusive')->defaultFalse()->end() |
113
|
3 |
|
->booleanNode('auto_delete')->defaultFalse()->end() |
114
|
3 |
|
->end() |
115
|
3 |
|
->end() |
116
|
3 |
|
->arrayNode('exchange_args') |
117
|
3 |
|
->addDefaultsIfNotSet() |
118
|
3 |
|
->children() |
119
|
3 |
|
->scalarNode('exchange')->defaultValue('dtc_queue_exchange')->end() |
120
|
3 |
|
->booleanNode('type')->defaultValue('direct')->end() |
121
|
3 |
|
->booleanNode('passive')->defaultFalse()->end() |
122
|
3 |
|
->booleanNode('durable')->defaultTrue()->end() |
123
|
3 |
|
->booleanNode('auto_delete')->defaultFalse()->end() |
124
|
3 |
|
->end() |
125
|
3 |
|
->end() |
126
|
3 |
|
->end() |
127
|
3 |
|
->validate()->always(function ($node) { |
128
|
1 |
|
if (empty($node['ssl_options'])) { |
129
|
1 |
|
unset($node['ssl_options']); |
130
|
|
|
} |
131
|
1 |
|
if (empty($node['options'])) { |
132
|
1 |
|
unset($node['options']); |
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
return $node; |
136
|
3 |
|
})->end() |
137
|
3 |
|
->validate()->ifTrue(function ($node) { |
138
|
1 |
|
if (isset($node['ssl_options']) && !$node['ssl']) { |
139
|
1 |
|
return true; |
140
|
|
|
} |
141
|
|
|
|
142
|
1 |
|
return false; |
143
|
3 |
|
})->thenInvalid('ssl must be true in order to set ssl_options')->end() |
144
|
|
|
->end() |
145
|
|
|
->end() |
146
|
|
|
; |
147
|
|
|
|
148
|
|
|
return $treeBuilder; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|