-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathConfiguration.php
More file actions
executable file
·236 lines (219 loc) · 9.26 KB
/
Configuration.php
File metadata and controls
executable file
·236 lines (219 loc) · 9.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
/**
* Copyright 2014 Underground Elephant
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package qpush-bundle
* @copyright Underground Elephant 2014
* @license Apache License, Version 2.0
*/
namespace Uecode\Bundle\QPushBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* @author Keith Kirk <kkirk@undergroundelephant.com>
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('uecode_qpush');
$rootNode
->addDefaultsIfNotSet()
->children()
->scalarNode('cache_service')
->defaultNull()
->end()
->booleanNode('logging_enabled')
->defaultTrue()
->end()
->append($this->getProvidersNode())
->append($this->getQueuesNode())
->end()
;
return $treeBuilder;
}
private function getProvidersNode()
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('providers');
$requirements = [
'aws' => [],
'ironmq' => ['token', 'project_id'],
'sync' => [],
'custom' => ['service'],
'file' => ['path']
];
$node
->useAttributeAsKey('name')
->prototype('array')
->treatNullLike([])
->children()
->enumNode('driver')
->isRequired()
->values(array_keys($requirements))
->end()
// IronMQ
->scalarNode('token')->end()
->scalarNode('project_id')->end()
->scalarNode('service')->end()
->enumNode('host')
->defaultValue('mq-aws-eu-west-1-1')
->values([
'mq-aws-eu-west-1-1',
'mq-aws-us-east-1-1',
])
->end()
->scalarNode('port')
->defaultValue('443')
->end()
->scalarNode('api_version')
->defaultValue(3)
->end()
// AWS
->scalarNode('key')->end()
->scalarNode('secret')->end()
->scalarNode('region')
->defaultValue('us-east-1')
->end()
// File
->scalarNode('path')->end()
->end()
->validate()
->always()
->then(function (array $provider) use ($node, $requirements) {
foreach ($requirements[$provider['driver']] as $requirement) {
if (empty($provider[$requirement])) {
throw new \InvalidArgumentException(
sprintf('%s queue providers must have a %s; none provided', $provider['driver'], $requirement)
);
}
}
return $provider;
})
->end()
;
return $node;
}
private function getQueuesNode()
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('queues');
$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('provider')
->isRequired()
->info('The Queue Provider to use')
->end()
->arrayNode('options')
->children()
->scalarNode('queue_name')
->defaultNull()
->info('The actual name of the queue')
->end()
->booleanNode('push_notifications')
->defaultFalse()
->info('Whether notifications are sent to the subscribers')
->end()
->booleanNode('push_notifications_only')
->defaultFalse()
->info('Where to disable queue polling')
->end()
->scalarNode('push_type')
->defaultValue('multicast')
->info('Whether the push queue is multicast or unicast')
->example('unicast')
->end()
->scalarNode('notification_retries')
->defaultValue(3)
->info('How many attempts the Push Notifications are retried if the Subscriber returns an error')
->example(3)
->end()
->scalarNode('notification_retries_delay')
->defaultValue(60)
->info('Delay between each Push Notification retry in seconds')
->example(3)
->end()
->scalarNode('message_delay')
->defaultValue(0)
->info('How many seconds before messages are inititally visible in the Queue')
->example(0)
->end()
->scalarNode('message_timeout')
->defaultValue(30)
->info('How many seconds the Queue hides a message while its being processed')
->example(30)
->end()
->scalarNode('message_expiration')
->defaultValue(604800)
->info('How many seconds a message is kept in Queue, the default is 7 days (604800 seconds)')
->example(604800)
->end()
->scalarNode('messages_to_receive')
->defaultValue(1)
->info('Max amount of messages to receive at once - an event will be fired for each individually')
->example(1)
->end()
->scalarNode('receive_wait_time')
->defaultValue(0)
->info('How many seconds to Long Poll when requesting messages - if supported')
->example(3)
->end()
->scalarNode('rate_limit')
->defaultValue(-1)
->info('How many push requests per second will be triggered. -1 for unlimited, 0 disables push')
->example(1)
->end()
->booleanNode('fifo')
->defaultFalse()
->info('If the queue is FIFO (aws)')
->end()
->booleanNode('content_based_deduplication')
->defaultFalse()
->info('If the FIFO queue has content based deduplication (aws)')
->end()
->append($this->getSubscribersNode())
->end()
->end()
->end()
->end()
;
return $node;
}
private function getSubscribersNode()
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('subscribers');
$node
->prototype('array')
->children()
->scalarNode('endpoint')
->info('The url or email address to notify')
->example('http://foo.bar/qpush/')
->end()
->enumNode('protocol')
->values(['email', 'http', 'https'])
->info('The endpoint type')
->example('http')
->end()
->end()
->end()
;
return $node;
}
}