1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mouf\AmqpClient\Objects; |
4
|
|
|
|
5
|
|
|
use Mouf\AmqpClient\RabbitMqObjectInterface; |
6
|
|
|
use PhpAmqpLib\Channel\AMQPChannel; |
7
|
|
|
|
8
|
|
|
class Binding implements RabbitMqObjectInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var Exchange |
12
|
|
|
*/ |
13
|
|
|
private $source; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Routing key. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $routing_key = ''; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* No wait. |
24
|
|
|
* |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private $nowait = false; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Arguments. |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private $arguments = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Ticket. |
38
|
|
|
* |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
private $ticket = 0; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Queue |
45
|
|
|
*/ |
46
|
|
|
private $to; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Parameter to initialize object only one time. |
50
|
|
|
* |
51
|
|
|
* @var bool |
52
|
|
|
*/ |
53
|
|
|
private $init = false; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set the source (Exchange) to the destination (Queue). |
57
|
|
|
* |
58
|
|
|
* @param Exchange $source |
59
|
|
|
* @param Queue $to |
60
|
|
|
*/ |
61
|
|
|
public function __construct(Exchange $source, Queue $to) |
62
|
|
|
{ |
63
|
|
|
$this->source = $source; |
64
|
|
|
$this->to = $to; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function init(AMQPChannel $amqpChannel) |
68
|
|
|
{ |
69
|
|
|
if (!$this->init) { |
70
|
|
|
$this->source->init($amqpChannel); |
71
|
|
|
$this->to->init($amqpChannel); |
72
|
|
|
|
73
|
|
|
$amqpChannel->queue_bind($this->to->getName(), |
74
|
|
|
$this->source->getName(), |
75
|
|
|
$this->routing_key, |
76
|
|
|
$this->nowait, |
77
|
|
|
$this->arguments, |
78
|
|
|
$this->ticket); |
79
|
|
|
|
80
|
|
|
$this->init = true; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get Routing key. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getRoutingKey() |
90
|
|
|
{ |
91
|
|
|
return $this->routing_key; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set routing key. |
96
|
|
|
* |
97
|
|
|
* @param string $routing_key |
98
|
|
|
* |
99
|
|
|
* @return Binding |
100
|
|
|
*/ |
101
|
|
|
public function setRoutingKey($routing_key) |
102
|
|
|
{ |
103
|
|
|
$this->routing_key = $routing_key; |
104
|
|
|
|
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get nowait. |
110
|
|
|
* |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
|
|
public function getNowait() |
114
|
|
|
{ |
115
|
|
|
return $this->nowait; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Set nowait. |
120
|
|
|
* |
121
|
|
|
* @param bool $nowait |
122
|
|
|
* |
123
|
|
|
* @return Binding |
124
|
|
|
*/ |
125
|
|
|
public function setNowait($nowait) |
126
|
|
|
{ |
127
|
|
|
$this->nowait = $nowait; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get arguments. |
134
|
|
|
* |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
public function getArguments() |
138
|
|
|
{ |
139
|
|
|
return $this->arguments; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Set arguments. |
144
|
|
|
* |
145
|
|
|
* @param bool $arguments |
146
|
|
|
* |
147
|
|
|
* @return Binding |
148
|
|
|
*/ |
149
|
|
|
public function setArguments(array $arguments) |
150
|
|
|
{ |
151
|
|
|
$this->arguments = $arguments; |
152
|
|
|
|
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get ticket. |
158
|
|
|
* |
159
|
|
|
* @return int |
160
|
|
|
*/ |
161
|
|
|
public function getTicket() |
162
|
|
|
{ |
163
|
|
|
return $this->ticket; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set ticket. |
168
|
|
|
* |
169
|
|
|
* @param int $ticket |
170
|
|
|
* |
171
|
|
|
* @return Binding |
172
|
|
|
*/ |
173
|
|
|
public function setTicket($ticket) |
174
|
|
|
{ |
175
|
|
|
$this->ticket = $ticket; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|