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\Iq\Query; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
use Kadet\Xmpp\Exception\InvalidArgumentException; |
20
|
|
|
use Kadet\Xmpp\Stanza\Iq\Query; |
21
|
|
|
use Kadet\Xmpp\Stanza\Iq\Query\Roster\Item; |
22
|
|
|
use function \Kadet\Xmpp\Utils\helper\format; |
23
|
|
|
use Kadet\Xmpp\Xml\XmlFactoryCollocations; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Roster |
27
|
|
|
* @package Kadet\Xmpp\Stanza\Iq\Query |
28
|
|
|
* |
29
|
|
|
* @property string $version Roster version (if server supports) |
30
|
|
|
* @property Query\Roster\Item[] $items Roster version (if server supports) |
31
|
|
|
*/ |
32
|
|
|
class Roster extends Query implements XmlFactoryCollocations |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Query constructor |
36
|
|
|
* |
37
|
|
|
* @param array $options { |
38
|
|
|
* @var mixed $content Content of element |
39
|
|
|
* @var array $attributes Element attributes |
40
|
|
|
* @var array string $version Roster version (if server supports) |
41
|
|
|
* @var Query\Roster\Item[] $items Roster version (if server supports) |
42
|
|
|
* } |
43
|
|
|
*/ |
44
|
|
|
public function __construct(array $options = []) |
45
|
|
|
{ |
46
|
|
|
parent::__construct('jabber:iq:roster', 'query', $options); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
#region Version |
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getVersion(): string |
55
|
|
|
{ |
56
|
|
|
return $this->getAttribute('ver'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $version |
61
|
|
|
*/ |
62
|
|
|
public function setVersion(string $version) |
63
|
|
|
{ |
64
|
|
|
$this->setAttribute('ver', $version); |
65
|
|
|
} |
66
|
|
|
#endregion |
67
|
|
|
|
68
|
|
|
#region Items |
69
|
|
|
/** |
70
|
|
|
* @return Query\Roster\Item[] |
71
|
|
|
*/ |
72
|
|
|
public function getItems(): array |
73
|
|
|
{ |
74
|
|
|
return $this->all(Item::class); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param Query\Roster\Item[] $items |
79
|
|
|
*/ |
80
|
|
|
public function setItems(array $items) |
81
|
|
|
{ |
82
|
|
|
$this->remove(\Kadet\Xmpp\Utils\filter\instance(Item::class)); |
83
|
|
|
$this->append($items); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
#endregion |
86
|
|
|
|
87
|
|
|
protected function appendChild($element) |
88
|
|
|
{ |
89
|
|
|
if(!$element instanceof Item) { |
90
|
|
|
throw new InvalidArgumentException(format('Only instances of roster item ({expected}) can be added into roster, tried to add {actual}', [ |
91
|
|
|
'expected' => Item::class, |
92
|
|
|
'actual' => get_class($element) |
93
|
|
|
])); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return parent::appendChild($element); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function getXmlCollocations() : array |
100
|
|
|
{ |
101
|
|
|
return [ |
102
|
|
|
[ Item::class, 'name' => 'item', 'uri' => 'jabber:iq:roster' ] |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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: