1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gidkom\OpenFireRestApi; |
4
|
|
|
|
5
|
|
|
use \Gidkom\OpenFireRestApi\RestClient; |
6
|
|
|
|
7
|
|
|
class OpenFireRestApi extends RestClient |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
public function __construct() |
12
|
|
|
{ |
13
|
|
|
parent::__construct(); |
14
|
|
|
|
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Get all registered users |
21
|
|
|
* |
22
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
23
|
|
|
*/ |
24
|
|
|
public function getUsers($opts = []) |
25
|
|
|
{ |
26
|
|
|
$query = ''; |
27
|
|
|
|
28
|
|
|
if(isset($opts['search'])) $query .= '?search='.$opts['search']; |
29
|
|
|
|
30
|
|
|
$endpoint = '/users'.$query; |
31
|
|
|
return $this->doRequest('GET', $endpoint); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get information for a specified user |
37
|
|
|
* |
38
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
39
|
|
|
*/ |
40
|
|
|
public function getUser($username) |
41
|
|
|
{ |
42
|
|
|
$endpoint = '/users/'.$username; |
43
|
|
|
return $this->doRequest('GET', $endpoint); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Creates a new OpenFire user |
49
|
|
|
* |
50
|
|
|
* @param string $username Username |
51
|
|
|
* @param string $password Password |
52
|
|
|
* @param string|false $name Name (Optional) |
53
|
|
|
* @param string|false $email Email (Optional) |
54
|
|
|
* @param string[]|false $groups Groups (Optional) |
55
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
56
|
|
|
*/ |
57
|
|
|
public function addUser($username, $password, $name=false, $email=false, $groups=false) |
58
|
|
|
{ |
59
|
|
|
$endpoint = '/users'; |
60
|
|
|
return $this->doRequest('POST', $endpoint, compact('username', 'password','name','email', 'groups')); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Deletes an OpenFire user |
66
|
|
|
* |
67
|
|
|
* @param string $username Username |
68
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
69
|
|
|
*/ |
70
|
|
|
public function deleteUser($username) |
71
|
|
|
{ |
72
|
|
|
$endpoint = '/users/'.$username; |
73
|
|
|
return $this->doRequest('DELETE', $endpoint); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Updates an OpenFire user |
78
|
|
|
* |
79
|
|
|
* @param string $username Username |
80
|
|
|
* @param string|false $password Password (Optional) |
81
|
|
|
* @param string|false $name Name (Optional) |
82
|
|
|
* @param string|false $email Email (Optional) |
83
|
|
|
* @param string[]|false $groups Groups (Optional) |
84
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
85
|
|
|
*/ |
86
|
|
|
public function updateUser($username, $password, $name=false, $email=false, $groups=false) |
87
|
|
|
{ |
88
|
|
|
$endpoint = '/users/'.$username; |
89
|
|
|
return $this->doRequest('PUT', $endpoint, compact('username', 'password','name','email', 'groups')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Retrieve all user groups |
95
|
|
|
* |
96
|
|
|
* @param string $username Username |
97
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
98
|
|
|
*/ |
99
|
|
|
public function userGroups($username) |
100
|
|
|
{ |
101
|
|
|
$endpoint = '/users/'.$username.'/groups'; |
102
|
|
|
return $this->doRequest('GET', $endpoint); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Add user to groups |
107
|
|
|
* |
108
|
|
|
* @param string $username Username |
109
|
|
|
* @param Array $groups Groups to add user |
110
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
111
|
|
|
*/ |
112
|
|
|
public function addToGroups($username, $groups) |
113
|
|
|
{ |
114
|
|
|
$endpoint = '/users/'.$username.'/groups'; |
115
|
|
|
return $this->doRequest('POST', $endpoint, $groups); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Add user to a group |
120
|
|
|
* |
121
|
|
|
* @param string $username Username |
122
|
|
|
* @param string $groups Groups to add user |
|
|
|
|
123
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
124
|
|
|
*/ |
125
|
|
|
public function addToGroup($username, $groupName) |
126
|
|
|
{ |
127
|
|
|
$endpoint = '/users/'.$username.'/groups/'.$groupName; |
128
|
|
|
return $this->doRequest('POST', $endpoint ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Delete user from a group |
134
|
|
|
* |
135
|
|
|
* @param string $username Username |
136
|
|
|
* @param string $groups Groups to add user |
|
|
|
|
137
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
138
|
|
|
*/ |
139
|
|
|
public function deleteFromGroup($username, $groupName) |
140
|
|
|
{ |
141
|
|
|
$endpoint = '/users/'.$username.'/groups/'.$groupName; |
142
|
|
|
return $this->doRequest('DELETE', $endpoint ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* lockout/Disable an OpenFire user |
148
|
|
|
* |
149
|
|
|
* @param string $username Username |
150
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
151
|
|
|
*/ |
152
|
|
|
public function lockoutUser($username) |
153
|
|
|
{ |
154
|
|
|
$endpoint = '/lockouts/'.$username; |
155
|
|
|
return $this->doRequest('POST', $endpoint); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* unlocks an OpenFire user |
161
|
|
|
* |
162
|
|
|
* @param string $username Username |
163
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
164
|
|
|
*/ |
165
|
|
|
public function unlockUser($username) |
166
|
|
|
{ |
167
|
|
|
$endpoint = '/lockouts/'.$username; |
168
|
|
|
return $this->doRequest('DELETE', $endpoint); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* List user rosters |
174
|
|
|
* |
175
|
|
|
* @param string $username Username |
176
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
177
|
|
|
*/ |
178
|
|
|
public function userRosters($username) |
179
|
|
|
{ |
180
|
|
|
$endpoint = '/users/'.$username.'/roster'; |
181
|
|
|
return $this->doRequest('GET', $endpoint, compact('jid','name','subscriptionType')); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Adds to this OpenFire user's roster |
187
|
|
|
* |
188
|
|
|
* @param string $username Username |
189
|
|
|
* @param string $jid JID |
190
|
|
|
* @param string|false $name Name (Optional) |
191
|
|
|
* @param int|false $subscriptionType Subscription (Optional) |
192
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
193
|
|
|
*/ |
194
|
|
|
public function addToRoster($username, $jid, $name=false, $subscriptionType=false) |
195
|
|
|
{ |
196
|
|
|
$endpoint = '/users/'.$username.'/roster'; |
197
|
|
|
return $this->doRequest('POST', $endpoint, compact('jid','name','subscriptionType')); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Removes from this OpenFire user's roster |
203
|
|
|
* |
204
|
|
|
* @param string $username Username |
205
|
|
|
* @param string $jid JID |
206
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
207
|
|
|
*/ |
208
|
|
|
public function deleteFromRoster($username, $jid) |
209
|
|
|
{ |
210
|
|
|
$endpoint = '/users/'.$username.'/roster/'.$jid; |
211
|
|
|
return $this->doRequest('DELETE', $endpoint, $jid); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Updates this OpenFire user's roster |
216
|
|
|
* |
217
|
|
|
* @param string $username Username |
218
|
|
|
* @param string $jid JID |
219
|
|
|
* @param string|false $nickname Nick Name (Optional) |
220
|
|
|
* @param int|false $subscriptionType Subscription (Optional) |
221
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
222
|
|
|
*/ |
223
|
|
|
public function updateRoster($username, $jid, $nickname=false, $subscriptionType=false) |
|
|
|
|
224
|
|
|
{ |
225
|
|
|
$endpoint = '/users/'.$username.'/roster/'.$jid; |
226
|
|
|
return $this->doRequest('PUT', $endpoint, $jid, compact('jid','username','subscriptionType')); |
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Get all groups |
231
|
|
|
* |
232
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
233
|
|
|
*/ |
234
|
|
|
public function getGroups() |
235
|
|
|
{ |
236
|
|
|
$endpoint = '/groups'; |
237
|
|
|
return $this->doRequest('GET', $endpoint); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Retrieve a group |
242
|
|
|
* |
243
|
|
|
* @param string $name Name of group |
244
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
245
|
|
|
*/ |
246
|
|
|
public function getGroup($name) |
247
|
|
|
{ |
248
|
|
|
$endpoint = '/groups/'.$name; |
249
|
|
|
return $this->doRequest('GET', $endpoint); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Create a group |
254
|
|
|
* |
255
|
|
|
* @param string $name Name of the group |
256
|
|
|
* @param string $description Some description of the group |
257
|
|
|
* |
258
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
259
|
|
|
*/ |
260
|
|
|
public function createGroup($name, $description = false) |
261
|
|
|
{ |
262
|
|
|
$endpoint = '/groups/'; |
263
|
|
|
return $this->doRequest('POST', $endpoint, compact('name','description')); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Delete a group |
268
|
|
|
* |
269
|
|
|
* @param string $name Name of the Group to delete |
270
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
271
|
|
|
*/ |
272
|
|
|
public function deleteGroup($name) |
273
|
|
|
{ |
274
|
|
|
$endpoint = '/groups/'.$name; |
275
|
|
|
return $this->doRequest('DELETE', $endpoint); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Update a group (description) |
280
|
|
|
* |
281
|
|
|
* @param string $name Name of group |
282
|
|
|
* @param string $description Some description of the group |
283
|
|
|
* |
284
|
|
|
*/ |
285
|
|
|
public function updateGroup($name, $description) |
286
|
|
|
{ |
287
|
|
|
$endpoint = '/groups/'.$name; |
288
|
|
|
return $this->doRequest('PUT', $endpoint, compact('name','description')); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Gell all active sessions |
293
|
|
|
* |
294
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
295
|
|
|
*/ |
296
|
|
|
public function getSessions() |
297
|
|
|
{ |
298
|
|
|
$endpoint = '/sessions'; |
299
|
|
|
return $this->doRequest('GET', $endpoint); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
public function getChatRoom($name) |
303
|
|
|
{ |
304
|
|
|
return $this->doRequest('GET', '/chatrooms/'.$name); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
public function getAllChatRooms() |
308
|
|
|
{ |
309
|
|
|
return $this->doRequest('GET', '/chatrooms?type=all'); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
public function createChatRoom($naturalName, $roomName, $description, $maxUsers = '30', $persistent = 'false', $publicRoom = 'false') |
313
|
|
|
{ |
314
|
|
|
$broadcastPresenceRoles = $this->bcastRoles; |
315
|
|
|
return $this->doRequest('POST', '/chatrooms', compact('naturalName', 'roomName', 'description', 'maxUsers', 'persistent', 'publicRoom', 'broadcastPresenceRoles')); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
public function deleteChatRoom($name) |
319
|
|
|
{ |
320
|
|
|
return $this->doRequest('DELETE', '/chatrooms/'.$name); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.