1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below). |
7
|
|
|
* |
8
|
|
|
* This program is free software; you can redistribute it and/or modify it under the |
9
|
|
|
* terms of the GNU Lesser General Public License as published by the Free Software |
10
|
|
|
* Foundation; either version 3.0 of the License, or (at your option) any later |
11
|
|
|
* version. |
12
|
|
|
* |
13
|
|
|
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY |
14
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
15
|
|
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Lesser General Public License along |
18
|
|
|
* with BigBlueButton; if not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace BigBlueButton; |
22
|
|
|
|
23
|
|
|
use BigBlueButton\Enum\HashingAlgorithm; |
24
|
|
|
use BigBlueButton\Exceptions\BadResponseException; |
25
|
|
|
use BigBlueButton\Parameters\CreateMeetingParameters; |
26
|
|
|
use BigBlueButton\Parameters\DeleteRecordingsParameters; |
27
|
|
|
use BigBlueButton\Parameters\EndMeetingParameters; |
28
|
|
|
use BigBlueButton\Parameters\GetMeetingInfoParameters; |
29
|
|
|
use BigBlueButton\Parameters\GetRecordingsParameters; |
30
|
|
|
use BigBlueButton\Parameters\GetRecordingTextTracksParameters; |
31
|
|
|
use BigBlueButton\Parameters\HooksCreateParameters; |
32
|
|
|
use BigBlueButton\Parameters\HooksDestroyParameters; |
33
|
|
|
use BigBlueButton\Parameters\InsertDocumentParameters; |
34
|
|
|
use BigBlueButton\Parameters\IsMeetingRunningParameters; |
35
|
|
|
use BigBlueButton\Parameters\JoinMeetingParameters; |
36
|
|
|
use BigBlueButton\Parameters\PublishRecordingsParameters; |
37
|
|
|
use BigBlueButton\Parameters\PutRecordingTextTrackParameters; |
38
|
|
|
use BigBlueButton\Parameters\UpdateRecordingsParameters; |
39
|
|
|
use BigBlueButton\Responses\ApiVersionResponse; |
40
|
|
|
use BigBlueButton\Responses\CreateMeetingResponse; |
41
|
|
|
use BigBlueButton\Responses\DeleteRecordingsResponse; |
42
|
|
|
use BigBlueButton\Responses\EndMeetingResponse; |
43
|
|
|
use BigBlueButton\Responses\GetMeetingInfoResponse; |
44
|
|
|
use BigBlueButton\Responses\GetMeetingsResponse; |
45
|
|
|
use BigBlueButton\Responses\GetRecordingsResponse; |
46
|
|
|
use BigBlueButton\Responses\GetRecordingTextTracksResponse; |
47
|
|
|
use BigBlueButton\Responses\HooksCreateResponse; |
48
|
|
|
use BigBlueButton\Responses\HooksDestroyResponse; |
49
|
|
|
use BigBlueButton\Responses\HooksListResponse; |
50
|
|
|
use BigBlueButton\Responses\IsMeetingRunningResponse; |
51
|
|
|
use BigBlueButton\Responses\JoinMeetingResponse; |
52
|
|
|
use BigBlueButton\Responses\PublishRecordingsResponse; |
53
|
|
|
use BigBlueButton\Responses\PutRecordingTextTrackResponse; |
54
|
|
|
use BigBlueButton\Responses\UpdateRecordingsResponse; |
55
|
|
|
use BigBlueButton\Util\UrlBuilder; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Class BigBlueButton. |
59
|
|
|
*/ |
60
|
|
|
class BigBlueButton |
61
|
|
|
{ |
62
|
|
|
/** |
63
|
|
|
* @deprecated This property has been replaced by property in UrlBuilder-class. |
64
|
|
|
* Use property via $this->getUrlBuilder()->setSecret() and $this->getUrlBuilder()->getSecret(). |
65
|
|
|
*/ |
66
|
|
|
protected string $bbbSecret; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @deprecated This property has been replaced by property in UrlBuilder-class. |
70
|
|
|
* Use property via $this->getUrlBuilder()->setServerBaseUrl() and $this->getUrlBuilder()->getServerBaseUrl(). |
71
|
|
|
*/ |
72
|
|
|
protected string $bbbBaseUrl; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @deprecated This property has been replaced by property in UrlBuilder-class. |
76
|
|
|
* User property via $this->getUrlBuilder()->setHashingAlgorithm() and $this->getUrlBuilder()->getHashingAlgorithm(). |
77
|
|
|
*/ |
78
|
|
|
protected string $hashingAlgorithm; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var array<int, mixed> |
82
|
|
|
*/ |
83
|
|
|
protected array $curlOpts = []; |
84
|
|
|
protected int $timeOut = 10; |
85
|
|
|
protected string $jSessionId; |
86
|
|
|
private UrlBuilder $urlBuilder; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param null|array<string, mixed> $opts |
90
|
|
|
*/ |
91
|
|
|
public function __construct(?string $baseUrl = null, ?string $secret = null, ?array $opts = []) |
92
|
|
|
{ |
93
|
|
|
// Provide an early error message if configuration is wrong |
94
|
|
|
if (is_null($baseUrl) && false === getenv('BBB_SERVER_BASE_URL')) { |
95
|
|
|
throw new \RuntimeException('No BBB-Server-Url found! Please provide it either in constructor ' . |
96
|
|
|
"(1st argument) or by environment variable 'BBB_SERVER_BASE_URL'!"); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if (is_null($secret) && false === getenv('BBB_SECRET') && false === getenv('BBB_SECURITY_SALT')) { |
100
|
|
|
throw new \RuntimeException('No BBB-Secret (or BBB-Salt) found! Please provide it either in constructor ' . |
101
|
|
|
"(2nd argument) or by environment variable 'BBB_SECRET' (or 'BBB_SECURITY_SALT')!"); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
// Keeping backward compatibility with older deployed versions |
105
|
|
|
// BBB_SECRET is the new variable name and have higher priority against the old named BBB_SECURITY_SALT |
106
|
|
|
// Reminder: getenv() will return FALSE if not set. But bool is not accepted by $this->bbbSecret |
107
|
|
|
// nor $this->bbbBaseUrl (only strings), thus FALSE will be converted automatically to an empty |
108
|
|
|
// string (''). Having a bool should be not possible due to the checks above and the automated |
109
|
|
|
// conversion, but PHPStan is still unhappy, so it's covered explicit by adding `?: ''`. |
110
|
|
|
$bbbBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL') ?: ''; |
111
|
|
|
$bbbSecret = $secret ?: getenv('BBB_SECRET') ?: getenv('BBB_SECURITY_SALT') ?: ''; |
112
|
|
|
$hashingAlgorithm = HashingAlgorithm::SHA_256; |
113
|
|
|
|
114
|
|
|
// initialize deprecated properties |
115
|
|
|
$this->bbbBaseUrl = $bbbBaseUrl; |
|
|
|
|
116
|
|
|
$this->bbbSecret = $bbbSecret; |
|
|
|
|
117
|
|
|
$this->hashingAlgorithm = $hashingAlgorithm; |
|
|
|
|
118
|
|
|
|
119
|
|
|
$this->urlBuilder = new UrlBuilder($bbbSecret, $bbbBaseUrl, $hashingAlgorithm); |
120
|
|
|
$this->curlOpts = $opts['curl'] ?? []; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @throws BadResponseException|\RuntimeException |
125
|
|
|
*/ |
126
|
|
|
public function getApiVersion(): ApiVersionResponse |
127
|
|
|
{ |
128
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->buildUrl()); |
129
|
|
|
|
130
|
|
|
return new ApiVersionResponse($xml); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
// __________________ BBB ADMINISTRATION METHODS _________________ |
134
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
135
|
|
|
-- create |
136
|
|
|
-- join |
137
|
|
|
-- end |
138
|
|
|
-- insertDocument |
139
|
|
|
*/ |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
143
|
|
|
*/ |
144
|
|
|
public function getCreateMeetingUrl(CreateMeetingParameters $createMeetingParams): string |
145
|
|
|
{ |
146
|
|
|
return $this->getUrlBuilder()->getCreateMeetingUrl($createMeetingParams); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @throws BadResponseException|\RuntimeException |
151
|
|
|
*/ |
152
|
|
|
public function createMeeting(CreateMeetingParameters $createMeetingParams): CreateMeetingResponse |
153
|
|
|
{ |
154
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML()); |
155
|
|
|
|
156
|
|
|
return new CreateMeetingResponse($xml); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
161
|
|
|
*/ |
162
|
|
|
public function getJoinMeetingURL(JoinMeetingParameters $joinMeetingParams): string |
163
|
|
|
{ |
164
|
|
|
return $this->getUrlBuilder()->getJoinMeetingURL($joinMeetingParams); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @throws BadResponseException|\RuntimeException |
169
|
|
|
*/ |
170
|
|
|
public function joinMeeting(JoinMeetingParameters $joinMeetingParams): JoinMeetingResponse |
171
|
|
|
{ |
172
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getJoinMeetingURL($joinMeetingParams)); |
173
|
|
|
|
174
|
|
|
return new JoinMeetingResponse($xml); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
179
|
|
|
*/ |
180
|
|
|
public function getEndMeetingURL(EndMeetingParameters $endParams): string |
181
|
|
|
{ |
182
|
|
|
return $this->getUrlBuilder()->getEndMeetingURL($endParams); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @throws BadResponseException|\RuntimeException |
187
|
|
|
*/ |
188
|
|
|
public function endMeeting(EndMeetingParameters $endParams): EndMeetingResponse |
189
|
|
|
{ |
190
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getEndMeetingURL($endParams)); |
191
|
|
|
|
192
|
|
|
return new EndMeetingResponse($xml); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
197
|
|
|
*/ |
198
|
|
|
public function getInsertDocumentUrl(InsertDocumentParameters $insertDocumentParameters): string |
199
|
|
|
{ |
200
|
|
|
return $this->getUrlBuilder()->getInsertDocumentUrl($insertDocumentParameters); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @throws BadResponseException|\RuntimeException |
205
|
|
|
*/ |
206
|
|
|
public function insertDocument(InsertDocumentParameters $insertDocumentParams): CreateMeetingResponse |
207
|
|
|
{ |
208
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getInsertDocumentUrl($insertDocumentParams), $insertDocumentParams->getPresentationsAsXML()); |
209
|
|
|
|
210
|
|
|
return new CreateMeetingResponse($xml); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
// __________________ BBB MONITORING METHODS _________________ |
214
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
215
|
|
|
-- isMeetingRunning |
216
|
|
|
-- getMeetings |
217
|
|
|
-- getMeetingInfo |
218
|
|
|
*/ |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
222
|
|
|
*/ |
223
|
|
|
public function getIsMeetingRunningUrl(IsMeetingRunningParameters $meetingParams): string |
224
|
|
|
{ |
225
|
|
|
return $this->getUrlBuilder()->getIsMeetingRunningUrl($meetingParams); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @throws BadResponseException|\RuntimeException |
230
|
|
|
*/ |
231
|
|
|
public function isMeetingRunning(IsMeetingRunningParameters $meetingParams): IsMeetingRunningResponse |
232
|
|
|
{ |
233
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getIsMeetingRunningUrl($meetingParams)); |
234
|
|
|
|
235
|
|
|
return new IsMeetingRunningResponse($xml); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Checks weather a meeting is existing. |
240
|
|
|
* |
241
|
|
|
* @throws BadResponseException |
242
|
|
|
*/ |
243
|
|
|
public function isMeetingExisting(string $meetingId): bool |
244
|
|
|
{ |
245
|
|
|
$getMeetingInfoParameters = new GetMeetingInfoParameters($meetingId); |
246
|
|
|
$meetingInfoResponse = $this->getMeetingInfo($getMeetingInfoParameters); |
247
|
|
|
|
248
|
|
|
return $meetingInfoResponse->success(); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
253
|
|
|
*/ |
254
|
|
|
public function getMeetingsUrl(): string |
255
|
|
|
{ |
256
|
|
|
return $this->getUrlBuilder()->getMeetingsUrl(); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @throws BadResponseException|\RuntimeException |
261
|
|
|
*/ |
262
|
|
|
public function getMeetings(): GetMeetingsResponse |
263
|
|
|
{ |
264
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getMeetingsUrl()); |
265
|
|
|
|
266
|
|
|
return new GetMeetingsResponse($xml); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
271
|
|
|
*/ |
272
|
|
|
public function getMeetingInfoUrl(GetMeetingInfoParameters $meetingParams): string |
273
|
|
|
{ |
274
|
|
|
return $this->getUrlBuilder()->getMeetingInfoUrl($meetingParams); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @throws BadResponseException|\RuntimeException |
279
|
|
|
*/ |
280
|
|
|
public function getMeetingInfo(GetMeetingInfoParameters $meetingParams): GetMeetingInfoResponse |
281
|
|
|
{ |
282
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getMeetingInfoUrl($meetingParams)); |
283
|
|
|
|
284
|
|
|
return new GetMeetingInfoResponse($xml); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
// __________________ BBB RECORDING METHODS _________________ |
288
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
289
|
|
|
-- getRecordings |
290
|
|
|
-- publishRecordings |
291
|
|
|
-- deleteRecordings |
292
|
|
|
*/ |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
296
|
|
|
*/ |
297
|
|
|
public function getRecordingsUrl(GetRecordingsParameters $recordingsParams): string |
298
|
|
|
{ |
299
|
|
|
return $this->getUrlBuilder()->getRecordingsUrl($recordingsParams); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @param mixed $recordingParams |
304
|
|
|
* |
305
|
|
|
* @throws BadResponseException|\RuntimeException |
306
|
|
|
*/ |
307
|
|
|
public function getRecordings($recordingParams): GetRecordingsResponse |
308
|
|
|
{ |
309
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getRecordingsUrl($recordingParams)); |
310
|
|
|
|
311
|
|
|
return new GetRecordingsResponse($xml); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
316
|
|
|
*/ |
317
|
|
|
public function getPublishRecordingsUrl(PublishRecordingsParameters $recordingParams): string |
318
|
|
|
{ |
319
|
|
|
return $this->getUrlBuilder()->getPublishRecordingsUrl($recordingParams); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @throws BadResponseException |
324
|
|
|
*/ |
325
|
|
|
public function publishRecordings(PublishRecordingsParameters $recordingParams): PublishRecordingsResponse |
326
|
|
|
{ |
327
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getPublishRecordingsUrl($recordingParams)); |
328
|
|
|
|
329
|
|
|
return new PublishRecordingsResponse($xml); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
334
|
|
|
*/ |
335
|
|
|
public function getDeleteRecordingsUrl(DeleteRecordingsParameters $recordingParams): string |
336
|
|
|
{ |
337
|
|
|
return $this->getUrlBuilder()->getDeleteRecordingsUrl($recordingParams); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @throws BadResponseException|\RuntimeException |
342
|
|
|
*/ |
343
|
|
|
public function deleteRecordings(DeleteRecordingsParameters $recordingParams): DeleteRecordingsResponse |
344
|
|
|
{ |
345
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getDeleteRecordingsUrl($recordingParams)); |
346
|
|
|
|
347
|
|
|
return new DeleteRecordingsResponse($xml); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
352
|
|
|
*/ |
353
|
|
|
public function getUpdateRecordingsUrl(UpdateRecordingsParameters $recordingParams): string |
354
|
|
|
{ |
355
|
|
|
return $this->getUrlBuilder()->getUpdateRecordingsUrl($recordingParams); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @throws BadResponseException|\RuntimeException |
360
|
|
|
*/ |
361
|
|
|
public function updateRecordings(UpdateRecordingsParameters $recordingParams): UpdateRecordingsResponse |
362
|
|
|
{ |
363
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getUpdateRecordingsUrl($recordingParams)); |
364
|
|
|
|
365
|
|
|
return new UpdateRecordingsResponse($xml); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
370
|
|
|
*/ |
371
|
|
|
public function getRecordingTextTracksUrl(GetRecordingTextTracksParameters $getRecordingTextTracksParameters): string |
372
|
|
|
{ |
373
|
|
|
return $this->getUrlBuilder()->getRecordingTextTracksUrl($getRecordingTextTracksParameters); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* @throws BadResponseException |
378
|
|
|
*/ |
379
|
|
|
public function getRecordingTextTracks(GetRecordingTextTracksParameters $getRecordingTextTracksParams): GetRecordingTextTracksResponse |
380
|
|
|
{ |
381
|
|
|
$json = $this->processJsonResponse($this->getUrlBuilder()->getRecordingTextTracksUrl($getRecordingTextTracksParams)); |
382
|
|
|
|
383
|
|
|
return new GetRecordingTextTracksResponse($json); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
388
|
|
|
*/ |
389
|
|
|
public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $putRecordingTextTrackParams): string |
390
|
|
|
{ |
391
|
|
|
return $this->getUrlBuilder()->getPutRecordingTextTrackUrl($putRecordingTextTrackParams); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @throws BadResponseException |
396
|
|
|
*/ |
397
|
|
|
public function putRecordingTextTrack(PutRecordingTextTrackParameters $putRecordingTextTrackParams): PutRecordingTextTrackResponse |
398
|
|
|
{ |
399
|
|
|
$json = $this->processJsonResponse($this->getUrlBuilder()->getPutRecordingTextTrackUrl($putRecordingTextTrackParams)); |
400
|
|
|
|
401
|
|
|
return new PutRecordingTextTrackResponse($json); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
// ____________________ WEB HOOKS METHODS ___________________ |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
408
|
|
|
*/ |
409
|
|
|
public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string |
410
|
|
|
{ |
411
|
|
|
return $this->getUrlBuilder()->getHooksCreateUrl($hookCreateParams); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* @param mixed $hookCreateParams |
416
|
|
|
* |
417
|
|
|
* @throws BadResponseException |
418
|
|
|
*/ |
419
|
|
|
public function hooksCreate($hookCreateParams): HooksCreateResponse |
420
|
|
|
{ |
421
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getHooksCreateUrl($hookCreateParams)); |
422
|
|
|
|
423
|
|
|
return new HooksCreateResponse($xml); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
428
|
|
|
*/ |
429
|
|
|
public function getHooksListUrl(): string |
430
|
|
|
{ |
431
|
|
|
return $this->getUrlBuilder()->getHooksListUrl(); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @throws BadResponseException |
436
|
|
|
*/ |
437
|
|
|
public function hooksList(): HooksListResponse |
438
|
|
|
{ |
439
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getHooksListUrl()); |
440
|
|
|
|
441
|
|
|
return new HooksListResponse($xml); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* @deprecated Replaced by same function-name provided by UrlBuilder-class |
446
|
|
|
*/ |
447
|
|
|
public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string |
448
|
|
|
{ |
449
|
|
|
return $this->getUrlBuilder()->getHooksDestroyUrl($hooksDestroyParams); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* @param mixed $hooksDestroyParams |
454
|
|
|
* |
455
|
|
|
* @throws BadResponseException |
456
|
|
|
*/ |
457
|
|
|
public function hooksDestroy($hooksDestroyParams): HooksDestroyResponse |
458
|
|
|
{ |
459
|
|
|
$xml = $this->processXmlResponse($this->getUrlBuilder()->getHooksDestroyUrl($hooksDestroyParams)); |
460
|
|
|
|
461
|
|
|
return new HooksDestroyResponse($xml); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
// ____________________ SPECIAL METHODS ___________________ |
465
|
|
|
|
466
|
|
|
public function getJSessionId(): string |
467
|
|
|
{ |
468
|
|
|
return $this->jSessionId; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
public function setJSessionId(string $jSessionId): void |
472
|
|
|
{ |
473
|
|
|
$this->jSessionId = $jSessionId; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* @param array<int, mixed> $curlOpts |
478
|
|
|
*/ |
479
|
|
|
public function setCurlOpts(array $curlOpts): void |
480
|
|
|
{ |
481
|
|
|
$this->curlOpts = $curlOpts; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* Set Curl Timeout (Optional), Default 10 Seconds. |
486
|
|
|
*/ |
487
|
|
|
public function setTimeOut(int $TimeOutInSeconds): self |
488
|
|
|
{ |
489
|
|
|
$this->timeOut = $TimeOutInSeconds; |
490
|
|
|
|
491
|
|
|
return $this; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
public function setHashingAlgorithm(string $hashingAlgorithm): void |
495
|
|
|
{ |
496
|
|
|
$this->hashingAlgorithm = $hashingAlgorithm; |
|
|
|
|
497
|
|
|
$this->getUrlBuilder()->setHashingAlgorithm($hashingAlgorithm); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
public function getHashingAlgorithm(string $hashingAlgorithm): string |
501
|
|
|
{ |
502
|
|
|
$this->hashingAlgorithm = $this->getUrlBuilder()->getHashingAlgorithm(); |
|
|
|
|
503
|
|
|
|
504
|
|
|
return $this->getUrlBuilder()->getHashingAlgorithm(); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* @deprecated Replaced by same function-name provided in UrlBuilder-class. |
509
|
|
|
* Access via $this->getUrlBuilder()->buildUrl() |
510
|
|
|
* |
511
|
|
|
* Public accessor for buildUrl |
512
|
|
|
*/ |
513
|
|
|
public function buildUrl(string $method = '', string $params = '', bool $append = true): string |
514
|
|
|
{ |
515
|
|
|
return $this->getUrlBuilder()->buildUrl($method, $params, $append); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
public function getUrlBuilder(): UrlBuilder |
519
|
|
|
{ |
520
|
|
|
return $this->urlBuilder; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
// ____________________ INTERNAL CLASS METHODS ___________________ |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* A private utility method used by other public methods to request HTTP responses. |
527
|
|
|
* |
528
|
|
|
* @throws BadResponseException|\RuntimeException |
529
|
|
|
*/ |
530
|
|
|
private function sendRequest(string $url, string $payload = '', string $contentType = 'application/xml'): string |
531
|
|
|
{ |
532
|
|
|
if (!extension_loaded('curl')) { |
533
|
|
|
throw new \RuntimeException('Post XML data set but curl PHP module is not installed or not enabled.'); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
$ch = curl_init(); |
537
|
|
|
$cookieFile = tmpfile(); |
538
|
|
|
|
539
|
|
|
if (!$ch) { // @phpstan-ignore-line |
540
|
|
|
throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch)); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
// JSESSIONID |
544
|
|
|
if ($cookieFile) { |
|
|
|
|
545
|
|
|
$cookieFilePath = stream_get_meta_data($cookieFile)['uri']; |
546
|
|
|
$cookies = file_get_contents($cookieFilePath); |
547
|
|
|
|
548
|
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFilePath); |
549
|
|
|
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFilePath); |
550
|
|
|
|
551
|
|
|
if ($cookies) { |
552
|
|
|
if (false !== mb_strpos($cookies, 'JSESSIONID')) { |
553
|
|
|
preg_match('/(?:JSESSIONID\s*)(?<JSESSIONID>.*)/', $cookies, $output_array); |
554
|
|
|
$this->setJSessionId($output_array['JSESSIONID']); |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
// PAYLOAD |
560
|
|
|
if (!empty($payload)) { |
561
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0); |
562
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); |
563
|
|
|
curl_setopt($ch, CURLOPT_POST, 1); |
564
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); |
565
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [ |
566
|
|
|
'Content-type: ' . $contentType, |
567
|
|
|
'Content-length: ' . mb_strlen($payload), |
568
|
|
|
]); |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
// OTHERS |
572
|
|
|
foreach ($this->curlOpts as $opt => $value) { |
573
|
|
|
curl_setopt($ch, $opt, $value); |
574
|
|
|
} |
575
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); |
576
|
|
|
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); |
577
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
578
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
579
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
580
|
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeOut); |
581
|
|
|
|
582
|
|
|
// EXECUTE and RESULT |
583
|
|
|
$data = curl_exec($ch); |
584
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
585
|
|
|
|
586
|
|
|
// ANALYSE |
587
|
|
|
if (false === $data) { |
588
|
|
|
throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch)); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
if (is_bool($data)) { |
592
|
|
|
throw new \RuntimeException('Curl error: BOOL received, but STRING expected.'); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
if ($httpCode < 200 || $httpCode >= 300) { |
596
|
|
|
throw new BadResponseException('Bad response, HTTP code: ' . $httpCode); |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
// CLOSE AND UNSET |
600
|
|
|
curl_close($ch); |
601
|
|
|
unset($ch); |
602
|
|
|
|
603
|
|
|
// RETURN |
604
|
|
|
return $data; |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* A private utility method used by other public methods to process XML responses. |
609
|
|
|
* |
610
|
|
|
* @throws BadResponseException|\Exception |
611
|
|
|
*/ |
612
|
|
|
private function processXmlResponse(string $url, string $payload = ''): \SimpleXMLElement |
613
|
|
|
{ |
614
|
|
|
$response = $this->sendRequest($url, $payload, $contentType); |
|
|
|
|
615
|
|
|
|
616
|
|
|
return new \SimpleXMLElement($response); |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* A private utility method used by other public methods to process json responses. |
621
|
|
|
* |
622
|
|
|
* @throws BadResponseException |
623
|
|
|
*/ |
624
|
|
|
private function processJsonResponse(string $url, string $payload = ''): string |
625
|
|
|
{ |
626
|
|
|
return $this->sendRequest($url, $payload, 'application/json'); |
627
|
|
|
} |
628
|
|
|
} |
629
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.