|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHPDaemon\Clients\AMQP\Driver; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Options related to AMQP connections. |
|
7
|
|
|
* |
|
8
|
|
|
* Class ConnectionOptions |
|
9
|
|
|
* @author Aleksey I. Kuleshov YOU GLOBAL LIMITED |
|
10
|
|
|
* @package PHPDaemon\Clients\AMQP\Driver |
|
11
|
|
|
*/ |
|
12
|
|
|
class ConnectionOptions |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string The hostname or IP address of the AMQP broker. |
|
16
|
|
|
*/ |
|
17
|
|
|
private $host; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var int The TCP port of the AMQP broker. |
|
21
|
|
|
*/ |
|
22
|
|
|
private $port; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string The username to use to authentication. |
|
26
|
|
|
*/ |
|
27
|
|
|
private $username; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string The password to use for authentication. |
|
31
|
|
|
*/ |
|
32
|
|
|
private $password; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string The virtual-host to use. |
|
36
|
|
|
*/ |
|
37
|
|
|
private $vhost; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string The product name to report to the broker. |
|
41
|
|
|
*/ |
|
42
|
|
|
private $productName; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string The product version to report to the broker. |
|
46
|
|
|
*/ |
|
47
|
|
|
private $productVersion; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var float|null The timeout in seconds (null = PHP default). |
|
51
|
|
|
*/ |
|
52
|
|
|
private $connectionTimeout; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var float|null The heartbeat interval in seconds (null = use broker suggestion). |
|
56
|
|
|
*/ |
|
57
|
|
|
private $heartbeatInterval; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $host The hostname or IP address of the AMQP broker. |
|
61
|
|
|
* @param int $port The TCP port of the AMQP broker. |
|
62
|
|
|
* @param string $username The username to use to authentication. |
|
63
|
|
|
* @param string $password The password to use for authentication. |
|
64
|
|
|
* @param string $vhost The virtual-host to use. |
|
65
|
|
|
*/ |
|
66
|
|
|
public function __construct( |
|
67
|
|
|
$host, |
|
68
|
|
|
$port, |
|
69
|
|
|
$username, |
|
70
|
|
|
$password, |
|
71
|
|
|
$vhost |
|
72
|
|
|
) |
|
73
|
|
|
{ |
|
74
|
|
|
assert( |
|
75
|
|
|
$port >= 1 && $port <= 65535, |
|
76
|
|
|
'Port must be between 1 and 65535, inclusive.' |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$this->host = $host; |
|
80
|
|
|
$this->port = $port; |
|
81
|
|
|
$this->username = $username; |
|
82
|
|
|
$this->password = $password; |
|
83
|
|
|
$this->vhost = $vhost; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get the hostname or IP address of the AMQP broker. |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getHost() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->host; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Set the hostname or IP address of the AMQP broker. |
|
97
|
|
|
* @param $host |
|
98
|
|
|
* @return ConnectionOptions |
|
99
|
|
|
*/ |
|
100
|
|
|
public function setHost($host) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->host = $host; |
|
103
|
|
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get the TCP port of the AMQP broker. |
|
108
|
|
|
* @return int |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getPort() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->port; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Set the TCP port of the AMQP broker. |
|
117
|
|
|
* @param $port |
|
118
|
|
|
* @return ConnectionOptions |
|
119
|
|
|
*/ |
|
120
|
|
|
public function setPort($port) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->port = $port; |
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get the username to use for authentication. |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getUsername() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->username; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Set the username to use for authentication. |
|
137
|
|
|
* @param $username |
|
138
|
|
|
* @return ConnectionOptions |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setUsername($username) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->username = $username; |
|
143
|
|
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Get the password to use for authentication. |
|
148
|
|
|
* @return string |
|
149
|
|
|
*/ |
|
150
|
|
|
public function getPassword() |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->password; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Set the password to use for authentication. |
|
157
|
|
|
* @param $password |
|
158
|
|
|
* @return ConnectionOptions |
|
159
|
|
|
*/ |
|
160
|
|
|
public function setPassword($password) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->password = $password; |
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Get the AMQP virtual-host to use. |
|
168
|
|
|
* @return string |
|
169
|
|
|
*/ |
|
170
|
|
|
public function getVhost() |
|
171
|
|
|
{ |
|
172
|
|
|
return $this->vhost; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Set the virtual-host to use. |
|
177
|
|
|
* @param $vhost |
|
178
|
|
|
* @return ConnectionOptions |
|
179
|
|
|
*/ |
|
180
|
|
|
public function setVhost($vhost) |
|
181
|
|
|
{ |
|
182
|
|
|
$this->vhost = $vhost; |
|
183
|
|
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Get the product name to report to the broker. |
|
188
|
|
|
* @return string |
|
189
|
|
|
*/ |
|
190
|
|
|
public function getProductName() |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->productName; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Set the product name to report to the broker. |
|
197
|
|
|
* @param string $name |
|
198
|
|
|
* @return ConnectionOptions |
|
199
|
|
|
*/ |
|
200
|
|
|
public function setProductName($name) |
|
201
|
|
|
{ |
|
202
|
|
|
$this->productName = $name; |
|
203
|
|
|
return $this; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Get the product version to report to the broker. |
|
208
|
|
|
* @return string |
|
209
|
|
|
*/ |
|
210
|
|
|
public function getProductVersion() |
|
211
|
|
|
{ |
|
212
|
|
|
return $this->productVersion; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Set the product version to report to the broker. |
|
217
|
|
|
* |
|
218
|
|
|
* @param string $version The product version. |
|
219
|
|
|
* @return ConnectionOptions |
|
220
|
|
|
*/ |
|
221
|
|
|
public function setProductVersion($version) |
|
222
|
|
|
{ |
|
223
|
|
|
$this->productVersion = $version; |
|
224
|
|
|
return $this; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Get the maximum time to allow for the connection to be established. |
|
229
|
|
|
* |
|
230
|
|
|
* @return float|null The timeout in seconds (null = PHP default). |
|
231
|
|
|
*/ |
|
232
|
|
|
public function getConnectionTimeout() |
|
233
|
|
|
{ |
|
234
|
|
|
return $this->connectionTimeout; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Set the maximum time to allow for the connection to be established. |
|
239
|
|
|
* |
|
240
|
|
|
* @param float|null $timeout The timeout in seconds (null = PHP default). |
|
241
|
|
|
* @return ConnectionOptions |
|
242
|
|
|
*/ |
|
243
|
|
|
public function setConnectionTimeout($timeout = null) |
|
244
|
|
|
{ |
|
245
|
|
|
$this->connectionTimeout = $timeout; |
|
246
|
|
|
return $this; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Get how often the broker and client must send heartbeat frames to keep |
|
251
|
|
|
* the connection alive. |
|
252
|
|
|
* |
|
253
|
|
|
* @return float|null The heartbeat interval in seconds (null = use broker suggestion). |
|
254
|
|
|
*/ |
|
255
|
|
|
public function getHeartbeatInterval() |
|
256
|
|
|
{ |
|
257
|
|
|
return $this->heartbeatInterval; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* Set how often the broker and client must send heartbeat frames to keep |
|
262
|
|
|
* the connection alive. |
|
263
|
|
|
* |
|
264
|
|
|
* @param float|null $interval The heartbeat interval in seconds (null = use broker suggestion). |
|
265
|
|
|
* @return ConnectionOptions |
|
266
|
|
|
*/ |
|
267
|
|
|
public function setHeartbeatInterval($interval = null) |
|
268
|
|
|
{ |
|
269
|
|
|
$this->heartbeatInterval = $interval; |
|
270
|
|
|
return $this; |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
|