1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nucleus - XMPP Library for PHP |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2016, 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\Stanza; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
use Kadet\Xmpp\Jid; |
20
|
|
|
use Kadet\Xmpp\Stanza\Iq\Query; |
21
|
|
|
use function Kadet\Xmpp\Utils\filter\pass; |
22
|
|
|
use Kadet\Xmpp\Xml\XmlElement; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Represents IQ Stanza |
26
|
|
|
* @package Kadet\Xmpp\Stanza |
27
|
|
|
* |
28
|
|
|
* @property Query $query |
29
|
|
|
*/ |
30
|
|
|
class Iq extends Stanza |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Stanza constructor. |
34
|
|
|
* @param string $type Iq query type |
35
|
|
|
* @param array $options { |
36
|
|
|
* @var Jid $from Jid representing "from" stanza attribute |
37
|
|
|
* @var Jid $to Jid representing "to" stanza attribute |
38
|
|
|
* @var string $id Unique id, will be generated if omitted |
39
|
|
|
* @var string $type Stanza type |
40
|
|
|
* @var mixed $content Stanza content |
41
|
|
|
* @var array $arguments Stanza arguments |
42
|
|
|
* @var Query $query Query associated with stanza |
43
|
|
|
* } |
44
|
|
|
*/ |
45
|
3 |
|
public function __construct(string $type, array $options = []) |
46
|
|
|
{ |
47
|
3 |
|
$this->type = $type; |
48
|
3 |
|
parent::__construct('iq', $options); |
49
|
3 |
|
} |
50
|
|
|
|
51
|
3 |
|
protected function appendChild($element) |
52
|
|
|
{ |
53
|
3 |
|
if(count($this->children) > 0) { |
54
|
|
|
throw new \RuntimeException('Iq stanzas cannot have more than one child.'); |
55
|
|
|
} |
56
|
|
|
|
57
|
3 |
|
return parent::appendChild($element); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
#region Query |
61
|
|
|
/** |
62
|
|
|
* @return Query |
63
|
|
|
*/ |
64
|
3 |
|
public function getQuery() |
65
|
|
|
{ |
66
|
3 |
|
return $this->get(Query::class); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Query $query |
71
|
|
|
*/ |
72
|
3 |
|
public function setQuery(Query $query) |
73
|
|
|
{ |
74
|
3 |
|
$this->remove($this->query); |
75
|
3 |
|
$this->append($query); |
76
|
3 |
|
} |
77
|
|
|
#endregion |
78
|
|
|
|
79
|
|
|
public static function getXmlCollocations() : array |
80
|
|
|
{ |
81
|
|
|
return array_merge( |
82
|
|
|
[[ Query::class, 'name' => pass(), 'uri' => pass() ]], |
83
|
|
|
parent::getXmlCollocations() |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|