1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 Fabian Grutschus. All rights reserved. |
5
|
|
|
* |
6
|
|
|
* Redistribution and use in source and binary forms, with or without modification, |
7
|
|
|
* are permitted provided that the following conditions are met: |
8
|
|
|
* |
9
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this |
10
|
|
|
* list of conditions and the following disclaimer. |
11
|
|
|
* |
12
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, |
13
|
|
|
* this list of conditions and the following disclaimer in the documentation |
14
|
|
|
* and/or other materials provided with the distribution. |
15
|
|
|
* |
16
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
20
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26
|
|
|
* |
27
|
|
|
* The views and conclusions contained in the software and documentation are those |
28
|
|
|
* of the authors and should not be interpreted as representing official policies, |
29
|
|
|
* either expressed or implied, of the copyright holders. |
30
|
|
|
* |
31
|
|
|
* @author Fabian Grutschus <[email protected]> |
32
|
|
|
* @copyright 2014 Fabian Grutschus. All rights reserved. |
33
|
|
|
* @license BSD |
34
|
|
|
* @link http://github.com/fabiang/xmpp |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
namespace Fabiang\Xmpp; |
38
|
|
|
|
39
|
|
|
use Fabiang\Xmpp\Connection\ConnectionInterface; |
40
|
|
|
use Fabiang\Xmpp\Protocol\ImplementationInterface; |
41
|
|
|
use Fabiang\Xmpp\Protocol\DefaultImplementation; |
42
|
|
|
use Psr\Log\LoggerInterface; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Xmpp connection options. |
46
|
|
|
* |
47
|
|
|
* @package Xmpp |
48
|
|
|
*/ |
49
|
|
|
class Options |
50
|
|
|
{ |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
* @var ImplementationInterface |
55
|
|
|
*/ |
56
|
|
|
protected $implementation; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
protected $address; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Connection object. |
66
|
|
|
* |
67
|
|
|
* @var ConnectionInterface |
68
|
|
|
*/ |
69
|
|
|
protected $connection; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* PSR-3 Logger interface. |
73
|
|
|
* |
74
|
|
|
* @var LoggerInterface |
75
|
|
|
*/ |
76
|
|
|
protected $logger; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
protected $to; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
protected $username; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* |
92
|
|
|
* @var string |
93
|
|
|
*/ |
94
|
|
|
protected $password; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* |
98
|
|
|
* @var string |
99
|
|
|
*/ |
100
|
|
|
protected $jid; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* |
104
|
|
|
* @var string |
105
|
|
|
*/ |
106
|
|
|
protected $sid; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* |
110
|
|
|
* @var boolean |
111
|
|
|
*/ |
112
|
|
|
protected $authenticated = false; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* |
116
|
|
|
* @var array |
117
|
|
|
*/ |
118
|
|
|
protected $users = []; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Timeout for connection. |
122
|
|
|
* |
123
|
|
|
* @var integer |
124
|
|
|
*/ |
125
|
|
|
protected $timeout = 30; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Authentication methods. |
129
|
|
|
* |
130
|
|
|
* @var array |
131
|
|
|
*/ |
132
|
|
|
protected $authenticationClasses = [ |
133
|
|
|
'digest-md5' => '\\Fabiang\\Xmpp\\EventListener\\Stream\\Authentication\\DigestMd5', |
134
|
|
|
'plain' => '\\Fabiang\\Xmpp\\EventListener\\Stream\\Authentication\\Plain', |
135
|
|
|
'anonymous' => '\\Fabiang\\Xmpp\\EventListener\\Stream\\Authentication\\Anonymous' |
136
|
3 |
|
]; |
137
|
|
|
|
138
|
3 |
|
|
139
|
3 |
|
/** |
140
|
3 |
|
* Options used to create a stream context |
141
|
3 |
|
* |
142
|
|
|
* @var array |
143
|
|
|
*/ |
144
|
|
|
protected $contextOptions = []; |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
3 |
|
* Constructor. |
149
|
|
|
* |
150
|
3 |
|
* @param string $address Server address |
151
|
3 |
|
*/ |
152
|
3 |
|
public function __construct($address = null) |
153
|
|
|
{ |
154
|
3 |
|
if (null !== $address) { |
155
|
|
|
$this->setAddress($address); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get protocol implementation. |
161
|
|
|
* |
162
|
|
|
* @return ImplementationInterface |
163
|
3 |
|
*/ |
164
|
|
|
public function getImplementation() |
165
|
3 |
|
{ |
166
|
3 |
|
if (null === $this->implementation) { |
167
|
|
|
$this->setImplementation(new DefaultImplementation()); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
return $this->implementation; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
3 |
|
* Set protocol implementation. |
175
|
|
|
* |
176
|
3 |
|
* @param ImplementationInterface $implementation |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
|
|
public function setImplementation(ImplementationInterface $implementation) |
180
|
|
|
{ |
181
|
|
|
$this->implementation = $implementation; |
182
|
|
|
return $this; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Get server address. |
187
|
3 |
|
* |
188
|
|
|
* @return string |
189
|
3 |
|
*/ |
190
|
3 |
|
public function getAddress() |
191
|
3 |
|
{ |
192
|
3 |
|
return $this->address; |
193
|
3 |
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Set server address. |
197
|
|
|
* |
198
|
|
|
* When a address is passed this setter also calls setTo with the hostname part of the address. |
199
|
|
|
* |
200
|
|
|
* @param string $address Server address |
201
|
3 |
|
* @return $this |
202
|
|
|
*/ |
203
|
3 |
|
public function setAddress($address) |
204
|
|
|
{ |
205
|
|
|
$this->address = (string) $address; |
206
|
|
|
if (false !== ($host = parse_url($address, PHP_URL_HOST))) { |
207
|
|
|
$this->setTo($host); |
208
|
|
|
} |
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
3 |
|
/** |
213
|
|
|
* Get connection object. |
214
|
3 |
|
* |
215
|
3 |
|
* @return ConnectionInterface |
216
|
|
|
*/ |
217
|
|
|
public function getConnection() |
218
|
|
|
{ |
219
|
|
|
return $this->connection; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
3 |
|
* Set connection object. |
224
|
|
|
* |
225
|
3 |
|
* @param ConnectionInterface $connection |
226
|
|
|
* @return $this |
227
|
|
|
*/ |
228
|
|
|
public function setConnection(ConnectionInterface $connection) |
229
|
|
|
{ |
230
|
|
|
$this->connection = $connection; |
231
|
|
|
return $this; |
232
|
|
|
} |
233
|
|
|
|
234
|
3 |
|
/** |
235
|
|
|
* Get logger instance. |
236
|
3 |
|
* |
237
|
3 |
|
* @return LoggerInterface |
238
|
|
|
*/ |
239
|
|
|
public function getLogger() |
240
|
|
|
{ |
241
|
|
|
return $this->logger; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
3 |
|
* Set logger instance. |
246
|
|
|
* |
247
|
3 |
|
* @param \Psr\Log\LoggerInterface $logger PSR-3 Logger |
248
|
|
|
* @return $this |
249
|
|
|
*/ |
250
|
|
|
public function setLogger(LoggerInterface $logger) |
251
|
|
|
{ |
252
|
|
|
$this->logger = $logger; |
253
|
|
|
return $this; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Get server name. |
258
|
3 |
|
* |
259
|
|
|
* @return string |
260
|
3 |
|
*/ |
261
|
3 |
|
public function getTo() |
262
|
|
|
{ |
263
|
|
|
return $this->to; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Set server name. |
268
|
|
|
* |
269
|
3 |
|
* This value is send to the server in requests as to="" attribute. |
270
|
|
|
* |
271
|
3 |
|
* @param string $to |
272
|
|
|
* @return $this |
273
|
|
|
*/ |
274
|
|
|
public function setTo($to) |
275
|
|
|
{ |
276
|
|
|
$this->to = (string) $to; |
277
|
|
|
return $this; |
278
|
|
|
} |
279
|
|
|
|
280
|
3 |
|
/** |
281
|
|
|
* Get username. |
282
|
3 |
|
* |
283
|
3 |
|
* @return string |
284
|
|
|
*/ |
285
|
|
|
public function getUsername() |
286
|
|
|
{ |
287
|
|
|
return $this->username; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Set username. |
292
|
|
|
* |
293
|
|
|
* @param string $username |
294
|
|
|
* @return $this |
295
|
|
|
*/ |
296
|
|
|
public function setUsername($username) |
297
|
|
|
{ |
298
|
|
|
$this->username = (string) $username; |
299
|
|
|
return $this; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
3 |
|
* Get resource. |
304
|
|
|
* |
305
|
3 |
|
* @return string |
306
|
|
|
*/ |
307
|
|
|
public function getResource() |
308
|
|
|
{ |
309
|
|
|
$username = $this->getUsername(); |
310
|
|
|
$username = explode('/', $username); |
311
|
|
|
return isset($username[1]) ? $username[1] : ''; |
312
|
|
|
} |
313
|
|
|
|
314
|
3 |
|
/** |
315
|
|
|
* Get password. |
316
|
3 |
|
* |
317
|
3 |
|
* @return string |
318
|
|
|
*/ |
319
|
|
|
public function getPassword() |
320
|
|
|
{ |
321
|
|
|
return $this->password; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
3 |
|
* Set password. |
326
|
|
|
* |
327
|
3 |
|
* @param string $password |
328
|
|
|
* @return $this |
329
|
|
|
*/ |
330
|
|
|
public function setPassword($password) |
331
|
|
|
{ |
332
|
|
|
$this->password = (string) $password; |
333
|
|
|
return $this; |
334
|
|
|
} |
335
|
|
|
|
336
|
3 |
|
/** |
337
|
|
|
* Get users jid. |
338
|
3 |
|
* |
339
|
3 |
|
* @return string |
340
|
|
|
*/ |
341
|
|
|
public function getJid() |
342
|
|
|
{ |
343
|
|
|
return $this->jid; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
3 |
|
* Set users jid. |
348
|
|
|
* |
349
|
3 |
|
* @param string $jid |
350
|
|
|
* @return $this |
351
|
|
|
*/ |
352
|
|
|
public function setJid($jid) |
353
|
|
|
{ |
354
|
|
|
$this->jid = (string) $jid; |
355
|
|
|
return $this; |
356
|
|
|
} |
357
|
|
|
|
358
|
3 |
|
/** |
359
|
|
|
* Get users jid. |
360
|
3 |
|
* |
361
|
3 |
|
* @return string |
362
|
|
|
*/ |
363
|
|
|
public function getSid() |
364
|
|
|
{ |
365
|
|
|
return $this->sid; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
3 |
|
* Set users jid. |
370
|
|
|
* |
371
|
3 |
|
* @param string $jid |
|
|
|
|
372
|
|
|
* @return $this |
373
|
|
|
*/ |
374
|
|
|
public function setSid($sid) |
375
|
|
|
{ |
376
|
|
|
$this->sid = (string) $sid; |
377
|
|
|
return $this; |
378
|
|
|
} |
379
|
|
|
|
380
|
3 |
|
/** |
381
|
|
|
* Is user authenticated. |
382
|
3 |
|
* |
383
|
3 |
|
* @return boolean |
384
|
|
|
*/ |
385
|
|
|
public function isAuthenticated() |
386
|
|
|
{ |
387
|
|
|
return $this->authenticated; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
3 |
|
* Set authenticated. |
392
|
|
|
* |
393
|
3 |
|
* @param boolean $authenticated Flag |
394
|
|
|
* @return $this |
395
|
|
|
*/ |
396
|
|
|
public function setAuthenticated($authenticated) |
397
|
|
|
{ |
398
|
|
|
$this->authenticated = (bool) $authenticated; |
399
|
|
|
return $this; |
400
|
|
|
} |
401
|
3 |
|
|
402
|
|
|
/** |
403
|
3 |
|
* Get users. |
404
|
3 |
|
* |
405
|
|
|
* @return Protocol\User\User[] |
406
|
|
|
*/ |
407
|
|
|
public function getUsers() |
408
|
|
|
{ |
409
|
|
|
return $this->users; |
410
|
|
|
} |
411
|
|
|
|
412
|
3 |
|
/** |
413
|
|
|
* Set users. |
414
|
3 |
|
* |
415
|
|
|
* @param array $users User list |
416
|
|
|
* @return $this |
417
|
|
|
*/ |
418
|
|
|
public function setUsers(array $users) |
419
|
|
|
{ |
420
|
|
|
$this->users = $users; |
421
|
|
|
return $this; |
422
|
|
|
} |
423
|
3 |
|
|
424
|
|
|
/** |
425
|
3 |
|
* Get authentication classes. |
426
|
3 |
|
* |
427
|
|
|
* @return array |
428
|
|
|
*/ |
429
|
|
|
public function getAuthenticationClasses() |
430
|
|
|
{ |
431
|
|
|
return $this->authenticationClasses; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* |
436
|
|
|
* @param array $authenticationClasses Authentication classes |
437
|
|
|
* @return $this |
438
|
|
|
*/ |
439
|
|
|
public function setAuthenticationClasses(array $authenticationClasses) |
440
|
|
|
{ |
441
|
|
|
$this->authenticationClasses = $authenticationClasses; |
442
|
|
|
return $this; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* Get timeout for connection. |
447
|
|
|
* |
448
|
|
|
* @return integer |
449
|
|
|
*/ |
450
|
|
|
public function getTimeout() |
451
|
|
|
{ |
452
|
|
|
return $this->timeout; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* Set timeout for connection. |
457
|
|
|
* |
458
|
|
|
* @param integer $timeout Seconds |
459
|
|
|
* @return \Fabiang\Xmpp\Options |
460
|
|
|
*/ |
461
|
|
|
public function setTimeout($timeout) |
462
|
|
|
{ |
463
|
|
|
$this->timeout = (int) $timeout; |
464
|
|
|
return $this; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* Get context options for connection |
469
|
|
|
* |
470
|
|
|
* @return array |
471
|
|
|
*/ |
472
|
|
|
public function getContextOptions() |
473
|
|
|
{ |
474
|
|
|
return $this->contextOptions; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Set context options for connection |
479
|
|
|
* |
480
|
|
|
* @param array $contextOptions |
481
|
|
|
* @return \Fabiang\Xmpp\Options |
482
|
|
|
*/ |
483
|
|
|
public function setContextOptions($contextOptions) |
484
|
|
|
{ |
485
|
|
|
$this->contextOptions = (array) $contextOptions; |
486
|
|
|
return $this; |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.