1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Transport\Rpc; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\Queue\QueueBagInterface; |
6
|
|
|
|
7
|
|
View Code Duplication |
class RpcQueueBag implements QueueBagInterface |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
private $options; |
10
|
|
|
|
11
|
|
|
public function __construct( |
12
|
|
|
$queue, |
13
|
|
|
$basicQos = 1, |
14
|
|
|
$passive = false, |
15
|
|
|
$durable = false, |
16
|
|
|
$exclusive = false, |
17
|
|
|
$autoDelete = true, |
18
|
|
|
$noWait = false, |
19
|
|
|
array $arguments = null, |
20
|
|
|
$ticket = null, |
21
|
|
|
$consumerTag = '', |
22
|
|
|
$noAck = false, |
23
|
|
|
$noLocal = false |
24
|
|
|
) { |
25
|
|
|
$this->options = [ |
26
|
|
|
'queue' => $queue, |
27
|
|
|
'basic_qos' => $basicQos, |
28
|
|
|
'passive' => $passive, |
29
|
|
|
'durable' => $durable, |
30
|
|
|
'exclusive' => $exclusive, |
31
|
|
|
'auto_delete' => $autoDelete, |
32
|
|
|
'no_wait' => $noWait, |
33
|
|
|
'arguments' => $arguments, |
34
|
|
|
'ticket' => $ticket, |
35
|
|
|
'consumer_tag' => $consumerTag, |
36
|
|
|
'no_ack' => $noAck, |
37
|
|
|
'no_local' => $noLocal, |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param $queue |
43
|
|
|
*/ |
44
|
|
|
public function setQueue($queue) |
45
|
|
|
{ |
46
|
|
|
$this->options['queue'] = $queue; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string|mixed |
51
|
|
|
*/ |
52
|
|
|
public function getQueue() |
53
|
|
|
{ |
54
|
|
|
return $this->options['queue']; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $qos |
59
|
|
|
*/ |
60
|
|
|
public function setBasicQos($qos) |
61
|
|
|
{ |
62
|
|
|
$this->options['basic_qos'] = $qos; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return int |
67
|
|
|
*/ |
68
|
|
|
public function getBasicQos() |
69
|
|
|
{ |
70
|
|
|
return $this->options['basic_qos']; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param $passive |
75
|
|
|
*/ |
76
|
|
|
public function setPassive($passive) |
77
|
|
|
{ |
78
|
|
|
$this->options['passive'] = $passive; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function getPassive() |
85
|
|
|
{ |
86
|
|
|
return $this->options['passive']; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param $durable |
91
|
|
|
*/ |
92
|
|
|
public function setDurable($durable) |
93
|
|
|
{ |
94
|
|
|
$this->options['durable'] = $durable; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
public function getDurable() |
101
|
|
|
{ |
102
|
|
|
return $this->options['durable']; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param $exclusive |
107
|
|
|
*/ |
108
|
|
|
public function setExclusive($exclusive) |
109
|
|
|
{ |
110
|
|
|
$this->options['exclusive'] = $exclusive; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
|
|
public function getExclusive() |
117
|
|
|
{ |
118
|
|
|
return $this->options['exclusive']; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param $autoDelete |
123
|
|
|
*/ |
124
|
|
|
public function setAutoDelete($autoDelete) |
125
|
|
|
{ |
126
|
|
|
$this->options['auto_delete'] = $autoDelete; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
|
|
public function getAutoDelete() |
133
|
|
|
{ |
134
|
|
|
return $this->options['auto_delete']; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param $noWait |
139
|
|
|
*/ |
140
|
|
|
public function setNoWait($noWait) |
141
|
|
|
{ |
142
|
|
|
$this->options['no_wait'] = $noWait; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return bool |
147
|
|
|
*/ |
148
|
|
|
public function getNoWait() |
149
|
|
|
{ |
150
|
|
|
return $this->options['no_wait']; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param array $arguments |
155
|
|
|
*/ |
156
|
|
|
public function setArguments(array $arguments) |
157
|
|
|
{ |
158
|
|
|
$this->options['arguments'] = $arguments; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
public function getArguments() |
165
|
|
|
{ |
166
|
|
|
return $this->options['arguments']; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param $ticket |
171
|
|
|
*/ |
172
|
|
|
public function setTicket($ticket) |
173
|
|
|
{ |
174
|
|
|
$this->options['ticket'] = $ticket; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return string |
179
|
|
|
*/ |
180
|
|
|
public function getTicket() |
181
|
|
|
{ |
182
|
|
|
return $this->options['ticket']; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param $consumerTag |
187
|
|
|
*/ |
188
|
|
|
public function setConsumerTag($consumerTag) |
189
|
|
|
{ |
190
|
|
|
$this->options['consumer_tag'] = $consumerTag; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return string |
195
|
|
|
*/ |
196
|
|
|
public function getConsumerTag() |
197
|
|
|
{ |
198
|
|
|
return $this->options['consumer_tag']; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @param $noAck |
203
|
|
|
*/ |
204
|
|
|
public function setNoAck($noAck) |
205
|
|
|
{ |
206
|
|
|
$this->options['no_ack'] = $noAck; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @return bool |
211
|
|
|
*/ |
212
|
|
|
public function getNoAck() |
213
|
|
|
{ |
214
|
|
|
return $this->options['no_ack']; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param $noLocal |
219
|
|
|
*/ |
220
|
|
|
public function setNoLocal($noLocal) |
221
|
|
|
{ |
222
|
|
|
$this->options['no_local'] = $noLocal; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @return bool |
227
|
|
|
*/ |
228
|
|
|
public function getNoLocal() |
229
|
|
|
{ |
230
|
|
|
return $this->options['no_local']; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return array |
235
|
|
|
*/ |
236
|
|
|
public function getQueueDeclare() |
237
|
|
|
{ |
238
|
|
|
return [ |
239
|
|
|
$this->getQueue(), |
240
|
|
|
$this->getPassive(), |
241
|
|
|
$this->getDurable(), |
242
|
|
|
$this->getExclusive(), |
243
|
|
|
$this->getAutoDelete(), |
244
|
|
|
$this->getNoWait(), |
245
|
|
|
$this->getArguments(), |
246
|
|
|
$this->getTicket(), |
247
|
|
|
]; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return array |
252
|
|
|
*/ |
253
|
|
|
public function getQueueConsume() |
254
|
|
|
{ |
255
|
|
|
return [ |
256
|
|
|
$this->getQueue(), |
257
|
|
|
$this->getConsumerTag(), |
258
|
|
|
$this->getNoLocal(), |
259
|
|
|
$this->getNoAck(), |
260
|
|
|
$this->getExclusive(), |
261
|
|
|
$this->getNoWait(), |
262
|
|
|
$this->getTicket(), |
263
|
|
|
$this->getArguments(), |
264
|
|
|
]; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @return array|false |
269
|
|
|
*/ |
270
|
|
|
public function getExchangeDeclare() |
271
|
|
|
{ |
272
|
|
|
return false; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @return string |
277
|
|
|
*/ |
278
|
|
|
public function getExchange() |
279
|
|
|
{ |
280
|
|
|
return false; |
|
|
|
|
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @return string |
285
|
|
|
*/ |
286
|
|
|
public function getType() |
287
|
|
|
{ |
288
|
|
|
return false; |
|
|
|
|
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
|
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.