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