1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* XMPP Library |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2016, Some right 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\Stanza; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
use Kadet\Xmpp\Jid; |
20
|
|
|
use Kadet\Xmpp\Xml\XmlElement; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class Stanza |
24
|
|
|
* @package Kadet\Xmpp\Stanza |
25
|
|
|
* |
26
|
|
|
* @property Jid|null $from Jid representing "from" stanza attribute |
27
|
|
|
* @property Jid|null $to Jid representing "to" stanza attribute |
28
|
|
|
* @property string $type Stanza type |
29
|
|
|
* @property string $id Unique stanza id |
30
|
|
|
*/ |
31
|
|
|
class Stanza extends XmlElement |
32
|
|
|
{ |
33
|
|
|
private $_from = false; |
34
|
|
|
private $_to = false; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Stanza constructor. |
38
|
|
|
* @param string $kind Stanza kind. According to XMPP RFC, one of "iq", "message", "presence" |
39
|
|
|
* @param array $options { |
40
|
|
|
* @var Jid $from Jid representing "from" stanza attribute |
41
|
|
|
* @var Jid $to Jid representing "to" stanza attribute |
42
|
|
|
* @var string $id Unique id, will be generated if omitted |
43
|
|
|
* @var string $type Stanza type |
44
|
|
|
* } |
45
|
|
|
* @param mixed $content Content to append |
46
|
|
|
*/ |
47
|
|
|
public function __construct(string $kind, array $options = [], $content = null) |
48
|
|
|
{ |
49
|
|
|
parent::__construct($kind, 'jabber:client', $content); |
50
|
|
|
|
51
|
|
|
$this->regenerateId($this->localName); |
52
|
|
|
$this->applyOptions($options); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getFrom() |
56
|
|
|
{ |
57
|
|
|
if($this->_from === false) { |
58
|
|
|
$this->_from = $this->hasAttribute('from') ? new Jid($this->_from) : null; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $this->_from; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getTo() |
65
|
|
|
{ |
66
|
|
|
if($this->_to === false) { |
67
|
|
|
$this->_to = $this->hasAttribute('to') ? new Jid($this->_to) : null; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $this->_to; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getType() |
74
|
|
|
{ |
75
|
|
|
return $this->getAttribute('type'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getId() |
79
|
|
|
{ |
80
|
|
|
return $this->getAttribute('id'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setFrom($from) |
84
|
|
|
{ |
85
|
|
|
if($from instanceof Jid) { |
86
|
|
|
$this->_from = $from instanceof Jid ? $from : new Jid($from); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->setAttribute('from', (string)$from); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function setTo($to) |
93
|
|
|
{ |
94
|
|
|
if($to instanceof Jid) { |
95
|
|
|
$this->_to = $to instanceof Jid ? $to : new Jid($to); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->setAttribute('to', (string)$to); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function setType(string $type) |
102
|
|
|
{ |
103
|
|
|
$this->setAttribute('type', $type); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setId(string $id) |
107
|
|
|
{ |
108
|
|
|
$this->setAttribute('id', $id); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function regenerateId(string $prefix = null) |
112
|
|
|
{ |
113
|
|
|
$this->id = uniqid($prefix, true); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function response() |
117
|
|
|
{ |
118
|
|
|
$response = static::plain($this->name, $this->namespace); |
119
|
|
|
|
120
|
|
|
$response->to = $this->from; |
121
|
|
|
$response->from = $this->to; |
122
|
|
|
$response->id = $this->id; |
123
|
|
|
|
124
|
|
|
return $response; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Initializes element with given name and URI |
129
|
|
|
* |
130
|
|
|
* @param string $name Element name, including prefix if needed |
131
|
|
|
* @param string $uri Namespace URI of element |
132
|
|
|
*/ |
133
|
|
|
protected function init(string $name, string $uri = null) |
134
|
|
|
{ |
135
|
|
|
parent::init($name, $uri); |
136
|
|
|
$this->regenerateId(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
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: