1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Transport\Subscriber; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\Queue\QueueBagInterface; |
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
7
|
|
|
|
8
|
|
|
class SubscriberQueueBag implements QueueBagInterface |
9
|
|
|
{ |
10
|
|
|
private $resolver; |
11
|
|
|
private $options; |
12
|
|
|
|
13
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
14
|
|
|
$exchangeName, |
15
|
|
|
$type = ExchangeType::FANOUT, |
16
|
|
|
$queueName = null, |
17
|
|
|
$basicQos = 1, |
18
|
|
|
array $arguments = null |
19
|
|
|
) { |
20
|
|
|
$this->resolver = new OptionsResolver(); |
21
|
|
|
$this->resolver->setDefaults([ |
22
|
|
|
'exchange' => $exchangeName, |
23
|
|
|
'type' => $type, |
24
|
|
|
'queue_name' => $queueName, |
25
|
|
|
'basic_qos' => $basicQos, |
26
|
|
|
'arguments' => $arguments |
27
|
|
|
]); |
28
|
|
|
$this->options = $this->resolver->resolve([]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param $exchange |
33
|
|
|
*/ |
34
|
|
|
public function setExchange($exchange) |
35
|
|
|
{ |
36
|
|
|
$this->options['exchange'] = $exchange; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string|mixed |
41
|
|
|
*/ |
42
|
|
|
public function getExchange() |
43
|
|
|
{ |
44
|
|
|
return $this->options['exchange']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param $qos |
49
|
|
|
*/ |
50
|
|
|
public function setBasicQos($qos) |
51
|
|
|
{ |
52
|
|
|
$this->options['basic_qos'] = $qos; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return int |
57
|
|
|
*/ |
58
|
|
|
public function getBasicQos() |
59
|
|
|
{ |
60
|
|
|
return $this->options['basic_qos']; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $queueName |
65
|
|
|
*/ |
66
|
|
|
public function setQueue($queueName) |
67
|
|
|
{ |
68
|
|
|
$this->options['queue_name'] = $queueName; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string|mixed |
74
|
|
|
*/ |
75
|
|
|
public function getQueue() |
76
|
|
|
{ |
77
|
|
|
return $this->options['queue_name']; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param $type |
82
|
|
|
*/ |
83
|
|
|
public function setType($type) |
84
|
|
|
{ |
85
|
|
|
$this->options['type'] = $type; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getType() |
92
|
|
|
{ |
93
|
|
|
return $this->options['type']; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
|
|
public function getPassive() |
100
|
|
|
{ |
101
|
|
|
return false; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param $internal |
106
|
|
|
*/ |
107
|
|
|
public function setInternal($internal) |
108
|
|
|
{ |
109
|
|
|
$this->options['internal'] = $internal; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param array $arguments |
114
|
|
|
*/ |
115
|
|
|
public function setArguments(array $arguments) |
116
|
|
|
{ |
117
|
|
|
$this->options['arguments'] = $arguments; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getArguments() |
124
|
|
|
{ |
125
|
|
|
return $this->options['arguments']; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
|
|
public function getInternal() |
132
|
|
|
{ |
133
|
|
|
return false; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return bool |
138
|
|
|
*/ |
139
|
|
|
public function getDurable() |
140
|
|
|
{ |
141
|
|
|
return false; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return bool |
146
|
|
|
*/ |
147
|
|
|
public function getAutoDelete() |
148
|
|
|
{ |
149
|
|
|
return false; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
public function getTicket() |
157
|
|
|
{ |
158
|
|
|
return null; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return bool |
163
|
|
|
*/ |
164
|
|
|
public function getNoAck() |
165
|
|
|
{ |
166
|
|
|
return true; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return bool |
171
|
|
|
*/ |
172
|
|
|
public function getNoLocal() |
173
|
|
|
{ |
174
|
|
|
return false; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return bool |
179
|
|
|
*/ |
180
|
|
|
public function getNoWait() |
181
|
|
|
{ |
182
|
|
|
return false; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return bool |
187
|
|
|
*/ |
188
|
|
|
public function getExclusive() |
189
|
|
|
{ |
190
|
|
|
return false; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return string |
195
|
|
|
*/ |
196
|
|
|
public function getConsumerTag() |
197
|
|
|
{ |
198
|
|
|
return ''; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return array |
203
|
|
|
*/ |
204
|
|
View Code Duplication |
public function getQueueDeclare() |
|
|
|
|
205
|
|
|
{ |
206
|
|
|
return [ |
207
|
|
|
$this->getQueue(), |
208
|
|
|
$this->getPassive(), |
209
|
|
|
$this->getDurable(), |
210
|
|
|
true, |
211
|
|
|
$this->getAutoDelete(), |
212
|
|
|
$this->getNoWait(), |
213
|
|
|
$this->getArguments(), |
214
|
|
|
$this->getTicket(), |
215
|
|
|
]; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return array |
220
|
|
|
*/ |
221
|
|
View Code Duplication |
public function getQueueConsume() |
|
|
|
|
222
|
|
|
{ |
223
|
|
|
return [ |
224
|
|
|
$this->getQueue(), |
225
|
|
|
$this->getConsumerTag(), |
226
|
|
|
$this->getNoLocal(), |
227
|
|
|
$this->getNoAck(), |
228
|
|
|
false, |
229
|
|
|
$this->getNoWait(), |
230
|
|
|
$this->getTicket(), |
231
|
|
|
$this->getArguments(), |
232
|
|
|
]; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
public function getExchangeDeclare() |
236
|
|
|
{ |
237
|
|
|
return [ |
238
|
|
|
$this->getExchange(), |
239
|
|
|
$this->getType(), |
240
|
|
|
$this->getPassive(), |
241
|
|
|
$this->getDurable(), |
242
|
|
|
$this->getAutoDelete(), |
243
|
|
|
$this->getInternal(), |
244
|
|
|
$this->getNoWait(), |
245
|
|
|
$this->getArguments(), |
246
|
|
|
$this->getTicket(), |
247
|
|
|
]; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @param array $options |
252
|
|
|
* @return QueueBagInterface |
253
|
|
|
*/ |
254
|
|
|
public function registerOptions(array $options) |
255
|
|
|
{ |
256
|
|
|
$this->options = $this->resolver->resolve($options); |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.