1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TreeHouse\Queue\Amqp\Driver\Amqp; |
4
|
|
|
|
5
|
|
|
use TreeHouse\Queue\Amqp\ChannelInterface; |
6
|
|
|
use TreeHouse\Queue\Amqp\QueueInterface; |
7
|
|
|
|
8
|
|
|
class Queue implements QueueInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var \AMQPQueue |
12
|
|
|
*/ |
13
|
|
|
protected $delegate; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var ChannelInterface |
17
|
|
|
*/ |
18
|
|
|
protected $channel; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var array<integer, integer> |
22
|
|
|
*/ |
23
|
|
|
protected static $flagMap = [ |
24
|
|
|
self::NOPARAM => AMQP_NOPARAM, |
25
|
|
|
self::DURABLE => AMQP_DURABLE, |
26
|
|
|
self::PASSIVE => AMQP_PASSIVE, |
27
|
|
|
self::EXCLUSIVE => AMQP_EXCLUSIVE, |
28
|
|
|
self::AUTODELETE => AMQP_AUTODELETE, |
29
|
|
|
self::MULTIPLE => AMQP_MULTIPLE, |
30
|
|
|
self::AUTOACK => AMQP_AUTOACK, |
31
|
|
|
self::REQUEUE => AMQP_REQUEUE, |
32
|
|
|
self::IFUNUSED => AMQP_IFUNUSED, |
33
|
|
|
self::IFEMPTY => AMQP_IFEMPTY, |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param \AMQPQueue $delegate |
38
|
|
|
* @param ChannelInterface $channel |
39
|
|
|
*/ |
40
|
3 |
|
public function __construct(\AMQPQueue $delegate, ChannelInterface $channel) |
41
|
|
|
{ |
42
|
3 |
|
$this->delegate = $delegate; |
43
|
3 |
|
$this->channel = $channel; |
44
|
3 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
1 |
|
public function getChannel() |
50
|
|
|
{ |
51
|
1 |
|
return $this->channel; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritdoc |
56
|
|
|
*/ |
57
|
1 |
|
public function getConnection() |
58
|
|
|
{ |
59
|
1 |
|
return $this->channel->getConnection(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritdoc |
64
|
|
|
*/ |
65
|
1 |
|
public function setName($name) |
66
|
|
|
{ |
67
|
1 |
|
return $this->delegate->setName($name); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @inheritdoc |
72
|
|
|
*/ |
73
|
2 |
|
public function getName() |
74
|
|
|
{ |
75
|
2 |
|
return $this->delegate->getName(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @inheritdoc |
80
|
|
|
*/ |
81
|
1 |
|
public function setArgument($key, $value) |
82
|
|
|
{ |
83
|
1 |
|
return $this->delegate->setArgument($key, $value); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritdoc |
88
|
|
|
*/ |
89
|
1 |
|
public function setArguments(array $arguments) |
90
|
|
|
{ |
91
|
1 |
|
return $this->delegate->setArguments($arguments); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @inheritdoc |
96
|
|
|
*/ |
97
|
2 |
|
public function getArgument($key) |
98
|
|
|
{ |
99
|
2 |
|
return $this->delegate->getArgument($key); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @inheritdoc |
104
|
|
|
*/ |
105
|
2 |
|
public function getArguments() |
106
|
|
|
{ |
107
|
2 |
|
return $this->delegate->getArguments(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @inheritdoc |
112
|
|
|
*/ |
113
|
1 |
|
public function hasArgument($key) |
114
|
|
|
{ |
115
|
1 |
|
return $this->delegate->hasArgument($key); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @inheritDoc |
120
|
|
|
*/ |
121
|
1 |
|
public function setFlags($flags) |
122
|
|
|
{ |
123
|
1 |
|
return $this->delegate->setFlags(self::convertToDelegateFlags($flags)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @inheritdoc |
128
|
|
|
*/ |
129
|
2 |
|
public function getFlags() |
130
|
|
|
{ |
131
|
2 |
|
return self::convertFromDelegateFlags($this->delegate->getFlags()); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @inheritdoc |
136
|
|
|
*/ |
137
|
|
|
public function getConsumerTag() |
138
|
|
|
{ |
139
|
|
|
return $this->delegate->getConsumerTag(); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @inheritdoc |
144
|
|
|
*/ |
145
|
1 |
|
public function declareQueue() |
146
|
|
|
{ |
147
|
1 |
|
return $this->delegate->declareQueue(); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @inheritdoc |
152
|
|
|
*/ |
153
|
1 |
|
public function bind($exchangeName, $routingKey, array $arguments = []) |
154
|
|
|
{ |
155
|
1 |
|
return $this->delegate->bind($exchangeName, $routingKey, $arguments); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @inheritdoc |
160
|
|
|
*/ |
161
|
|
|
public function unbind($exchangeName, $routingKey = null, array $arguments = []) |
162
|
|
|
{ |
163
|
|
|
return $this->delegate->unbind($exchangeName, $routingKey, $arguments); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @inheritdoc |
168
|
|
|
*/ |
169
|
1 |
View Code Duplication |
public function get($flags = null) |
|
|
|
|
170
|
|
|
{ |
171
|
1 |
|
if (false !== $envelope = $this->delegate->get(self::convertToDelegateFlags($flags))) { |
172
|
1 |
|
$envelope = new Envelope($envelope); |
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
175
|
1 |
|
return $envelope; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @inheritdoc |
180
|
|
|
*/ |
181
|
|
View Code Duplication |
public function consume(callable $callback, $flags = null, $consumerTag = null) |
|
|
|
|
182
|
|
|
{ |
183
|
|
|
$wrapper = function (\AMQPEnvelope $envelope) use ($callback) { |
184
|
|
|
return $callback(new Envelope($envelope)); |
185
|
|
|
}; |
186
|
|
|
|
187
|
|
|
$this->delegate->consume($wrapper, self::convertToDelegateFlags($flags), $consumerTag); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @inheritdoc |
192
|
|
|
*/ |
193
|
|
|
public function ack($deliveryTag, $flags = null) |
194
|
|
|
{ |
195
|
|
|
return $this->delegate->ack($deliveryTag, self::convertToDelegateFlags($flags)); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @inheritdoc |
200
|
|
|
*/ |
201
|
|
|
public function nack($deliveryTag, $flags = AMQP_NOPARAM) |
202
|
|
|
{ |
203
|
|
|
$this->delegate->nack($deliveryTag, self::convertToDelegateFlags($flags)); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @inheritdoc |
208
|
|
|
*/ |
209
|
|
|
public function reject($deliveryTag, $flags = AMQP_NOPARAM) |
210
|
|
|
{ |
211
|
|
|
$this->delegate->reject($deliveryTag, self::convertToDelegateFlags($flags)); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @inheritdoc |
216
|
|
|
*/ |
217
|
|
|
public function cancel($consumerTag = '') |
218
|
|
|
{ |
219
|
|
|
return $this->delegate->cancel($consumerTag); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @inheritdoc |
224
|
|
|
*/ |
225
|
3 |
|
public function delete($flags = null) |
226
|
|
|
{ |
227
|
3 |
|
$this->delegate->delete(self::convertToDelegateFlags($flags)); |
228
|
3 |
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @inheritdoc |
232
|
|
|
*/ |
233
|
|
|
public function purge() |
234
|
|
|
{ |
235
|
|
|
$this->delegate->purge(); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @inheritdoc |
240
|
|
|
* |
241
|
|
|
* @return \AMQPQueue |
242
|
|
|
*/ |
243
|
|
|
public function getDelegate() |
244
|
|
|
{ |
245
|
|
|
return $this->delegate; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param int|null $flags |
250
|
|
|
* |
251
|
|
|
* @return int |
252
|
|
|
*/ |
253
|
4 |
View Code Duplication |
public static function convertToDelegateFlags($flags = null) |
|
|
|
|
254
|
|
|
{ |
255
|
4 |
|
if (null === $flags) { |
256
|
3 |
|
return AMQP_NOPARAM; |
257
|
|
|
} |
258
|
|
|
|
259
|
3 |
|
$converted = 0; |
260
|
|
|
|
261
|
3 |
|
foreach (self::$flagMap as $from => $to) { |
262
|
3 |
|
if ($flags & $from) { |
263
|
3 |
|
$converted |= $to; |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|
267
|
3 |
|
return $converted; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @param int|null $flags |
272
|
|
|
* |
273
|
|
|
* @return int |
274
|
|
|
*/ |
275
|
3 |
View Code Duplication |
public static function convertFromDelegateFlags($flags = null) |
|
|
|
|
276
|
|
|
{ |
277
|
3 |
|
if (null === $flags) { |
278
|
|
|
return self::NOPARAM; |
279
|
|
|
} |
280
|
|
|
|
281
|
3 |
|
$converted = 0; |
282
|
|
|
|
283
|
3 |
|
foreach (self::$flagMap as $from => $to) { |
284
|
3 |
|
if ($flags & $to) { |
285
|
3 |
|
$converted |= $from; |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
289
|
3 |
|
return $converted; |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.