1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\NotificationBundle\Iterator; |
13
|
|
|
|
14
|
|
|
use Interop\Amqp\AmqpConsumer; |
15
|
|
|
use Interop\Amqp\AmqpMessage; |
16
|
|
|
use PhpAmqpLib\Channel\AMQPChannel; |
17
|
|
|
use Sonata\NotificationBundle\Model\Message; |
18
|
|
|
|
19
|
|
|
class AMQPMessageIterator implements MessageIteratorInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var mixed |
23
|
|
|
*/ |
24
|
|
|
protected $message; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var AmqpMessage |
28
|
|
|
*/ |
29
|
|
|
protected $AMQMessage; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int |
33
|
|
|
*/ |
34
|
|
|
protected $counter; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
protected $timeout; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var AmqpConsumer |
43
|
|
|
*/ |
44
|
|
|
protected $consumer; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var bool |
48
|
|
|
*/ |
49
|
|
|
protected $isValid; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @deprecated since 3.2, will be removed in 4.x |
53
|
|
|
* |
54
|
|
|
* @var AMQPChannel |
55
|
|
|
*/ |
56
|
|
|
protected $channel; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @deprecated since 3.2, will be removed in 4.x |
60
|
|
|
* |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
protected $queue; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param AMQPChannel $channel |
67
|
|
|
* @param AmqpConsumer $consumer |
68
|
|
|
*/ |
69
|
|
|
public function __construct(AMQPChannel $channel, AmqpConsumer $consumer) |
70
|
|
|
{ |
71
|
|
|
$this->consumer = $consumer; |
72
|
|
|
$this->counter = 0; |
73
|
|
|
$this->timeout = 0; |
74
|
|
|
$this->isValid = true; |
75
|
|
|
|
76
|
|
|
$this->channel = $channel; |
|
|
|
|
77
|
|
|
$this->queue = $consumer->getQueue()->getQueueName(); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function current() |
84
|
|
|
{ |
85
|
|
|
return $this->message; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
public function next() |
92
|
|
|
{ |
93
|
|
|
if ($amqpMessage = $this->consumer->receive($this->timeout)) { |
94
|
|
|
$this->AMQMessage = $amqpMessage; |
95
|
|
|
|
96
|
|
|
$data = json_decode($this->AMQMessage->getBody(), true); |
97
|
|
|
$data['body']['AMQMessage'] = $amqpMessage; |
98
|
|
|
|
99
|
|
|
$message = new Message(); |
100
|
|
|
$message->setBody($data['body']); |
101
|
|
|
$message->setType($data['type']); |
102
|
|
|
$message->setState($data['state']); |
103
|
|
|
$this->message = $message; |
104
|
|
|
|
105
|
|
|
++$this->counter; |
106
|
|
|
$this->isValid = true; |
107
|
|
|
} else { |
108
|
|
|
$this->isValid = false; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
|
|
public function key() |
116
|
|
|
{ |
117
|
|
|
$this->counter; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
|
public function valid() |
124
|
|
|
{ |
125
|
|
|
return $this->isValid; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritdoc} |
130
|
|
|
*/ |
131
|
|
|
public function rewind() |
132
|
|
|
{ |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.