1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nucleus - XMPP Library for PHP |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2017, Some rights reserved. |
6
|
|
|
* |
7
|
|
|
* @author Kacper "Kadet" Donat <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Contact with author: |
10
|
|
|
* Xmpp: [email protected] |
11
|
|
|
* E-mail: [email protected] |
12
|
|
|
* |
13
|
|
|
* From Kadet with love. |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Kadet\Xmpp\Component\Subscription; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
use Kadet\Xmpp\Component\Component; |
20
|
|
|
use Kadet\Xmpp\Jid; |
21
|
|
|
use Kadet\Xmpp\Stanza\Presence; |
22
|
|
|
use Kadet\Xmpp\Utils\BetterEmitter; |
23
|
|
|
|
24
|
|
|
use function \Kadet\Xmpp\Utils\filter\{ |
25
|
|
|
stanza\type, in |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
class SubscriptionManager extends Component |
29
|
|
|
{ |
30
|
|
|
use BetterEmitter; |
31
|
|
|
|
32
|
|
|
protected function init() |
33
|
|
|
{ |
34
|
4 |
|
$this->_client->on('presence', function(...$args) { |
35
|
1 |
|
$this->handleSubscriptionRequest(...$args); |
|
|
|
|
36
|
4 |
|
}, type('subscribe')); |
37
|
4 |
|
} |
38
|
|
|
|
39
|
1 |
|
private function handleSubscriptionRequest(Presence $presence) |
40
|
|
|
{ |
41
|
1 |
|
$this->emit('request', [ $presence ]); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Sends subscription request presence to server. |
46
|
|
|
* |
47
|
|
|
* @param Jid|string $jid |
48
|
|
|
* @return \React\Promise\ExtendedPromiseInterface |
49
|
|
|
*/ |
50
|
1 |
|
public function subscribe($jid) |
51
|
|
|
{ |
52
|
1 |
|
return $this->_client->send($this->presence('subscribe', $jid)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Sends subscription removal request presence to server. |
57
|
|
|
* |
58
|
|
|
* @param Jid|string $jid |
59
|
|
|
* @return \React\Promise\ExtendedPromiseInterface |
60
|
|
|
*/ |
61
|
1 |
|
public function unsubscribe(Jid $jid) |
62
|
|
|
{ |
63
|
1 |
|
return $this->_client->send($this->presence('unsubscribe', $jid)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Sends subscription cancellation request presence to server. |
68
|
|
|
* |
69
|
|
|
* @param Jid|string $jid |
70
|
|
|
* @return \React\Promise\ExtendedPromiseInterface |
71
|
|
|
*/ |
72
|
1 |
|
public function cancel($jid) |
73
|
|
|
{ |
74
|
1 |
|
return $this->_client->send($this->presence('unsubscribed', $jid)); |
75
|
|
|
} |
76
|
|
|
|
77
|
3 |
|
private function presence($type, $jid) |
78
|
|
|
{ |
79
|
3 |
|
$jid = $jid instanceof Jid ? $jid : new Jid($jid); |
80
|
3 |
|
return new Presence([ |
81
|
3 |
|
'type' => $type, |
82
|
3 |
|
'to' => $jid->bare() |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: