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 XmlElement $query |
29
|
|
|
*/ |
30
|
|
|
class Iq extends Stanza |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Stanza constructor. |
34
|
|
|
* @param array $options { |
35
|
|
|
* @var Jid $from Jid representing "from" stanza attribute |
36
|
|
|
* @var Jid $to Jid representing "to" stanza attribute |
37
|
|
|
* @var string $id Unique id, will be generated if omitted |
38
|
|
|
* @var string $type Stanza type |
39
|
|
|
* @var mixed $content Stanza content |
40
|
|
|
* @var array $arguments Stanza arguments |
41
|
|
|
* @var Query $query Query associated with stanza |
42
|
|
|
* } |
43
|
|
|
*/ |
44
|
|
|
public function __construct(array $options) |
45
|
|
|
{ |
46
|
|
|
parent::__construct('iq', $options); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function appendChild($element) |
50
|
|
|
{ |
51
|
|
|
if(count($this->children) > 0) { |
52
|
|
|
throw new \RuntimeException('Iq stanzas cannot have more than one child.'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return parent::appendChild($element); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
#region Query |
59
|
|
|
/** |
60
|
|
|
* @return Query |
61
|
|
|
*/ |
62
|
|
|
public function getQuery() |
63
|
|
|
{ |
64
|
|
|
return $this->get(Query::class); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Query $query |
69
|
|
|
*/ |
70
|
|
|
public function setQuery(Query $query) |
71
|
|
|
{ |
72
|
|
|
$this->remove($this->query); |
73
|
|
|
$this->append($query); |
74
|
|
|
} |
75
|
|
|
#endregion |
76
|
|
|
|
77
|
|
|
public static function getXmlCollocations() : array |
78
|
|
|
{ |
79
|
|
|
return array_merge( |
80
|
|
|
[[ Query::class, 'name' => pass(), 'uri' => pass() ]], |
81
|
|
|
parent::getXmlCollocations() |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|