@@ -18,7 +18,7 @@ |
||
| 18 | 18 | { |
| 19 | 19 | parent::__construct($init); |
| 20 | 20 | if ($init) |
| 21 | - $this->data->fullName = $fullName; |
|
| 21 | + $this->data->fullName = $fullName; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -18,8 +18,9 @@ discard block |
||
| 18 | 18 | public function __construct(string $fullName, bool $init = true) |
| 19 | 19 | { |
| 20 | 20 | parent::__construct($init); |
| 21 | - if ($init) |
|
| 22 | - $this->data->fullName = $fullName; |
|
| 21 | + if ($init) { |
|
| 22 | + $this->data->fullName = $fullName; |
|
| 23 | + } |
|
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | /** |
@@ -77,7 +78,9 @@ discard block |
||
| 77 | 78 | */ |
| 78 | 79 | public function addTag(string $tag): Event |
| 79 | 80 | { |
| 80 | - if (!isset($this->data->tags)) $this->data->tags = ''; |
|
| 81 | + if (!isset($this->data->tags)) { |
|
| 82 | + $this->data->tags = ''; |
|
| 83 | + } |
|
| 81 | 84 | |
| 82 | 85 | $this->data->tags .= rtrim($tag, ',') . ','; |
| 83 | 86 | |
@@ -156,8 +159,9 @@ discard block |
||
| 156 | 159 | private function set_fields(array &$array, array $map): void |
| 157 | 160 | { |
| 158 | 161 | foreach ($map as $key => $value) { |
| 159 | - if ($value) |
|
| 160 | - $array[$key] = $value; |
|
| 162 | + if ($value) { |
|
| 163 | + $array[$key] = $value; |
|
| 164 | + } |
|
| 161 | 165 | } |
| 162 | 166 | } |
| 163 | 167 | |
@@ -180,7 +184,9 @@ discard block |
||
| 180 | 184 | */ |
| 181 | 185 | public function validate(bool $exists = false): void |
| 182 | 186 | { |
| 183 | - if (!$this->data->fullName ?? null) throw new InValidResourceException('Event', 'fullName'); |
|
| 187 | + if (!$this->data->fullName ?? null) { |
|
| 188 | + throw new InValidResourceException('Event', 'fullName'); |
|
| 189 | + } |
|
| 184 | 190 | |
| 185 | 191 | if (($this->data->isPasswordProtected ?? false) && (!$this->data->password ?? null)) { |
| 186 | 192 | throw new InValidResourceException('Event', 'password (password must be present for a password protected event)'); |
@@ -21,7 +21,9 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function __construct(bool $init = true) |
| 23 | 23 | { |
| 24 | - if ($init) $this->data = new stdClass(); |
|
| 24 | + if ($init) { |
|
| 25 | + $this->data = new stdClass(); |
|
| 26 | + } |
|
| 25 | 27 | } |
| 26 | 28 | |
| 27 | 29 | /** |
@@ -32,7 +34,9 @@ discard block |
||
| 32 | 34 | */ |
| 33 | 35 | public static function fromObject(object $object): Resource |
| 34 | 36 | { |
| 35 | - if ($object == null) return null; |
|
| 37 | + if ($object == null) { |
|
| 38 | + return null; |
|
| 39 | + } |
|
| 36 | 40 | |
| 37 | 41 | $instance = new static(false); |
| 38 | 42 | $instance->data = $object; |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | $events = []; |
| 237 | 237 | |
| 238 | 238 | $response = $this->request("accounts/{$accountId}/{$type}_events", 'get', null, [ |
| 239 | - 'page' => $page, |
|
| 240 | - 'maxItems' => $maxItems, |
|
| 241 | - 'order' => $order |
|
| 239 | + 'page' => $page, |
|
| 240 | + 'maxItems' => $maxItems, |
|
| 241 | + 'order' => $order |
|
| 242 | 242 | ]); |
| 243 | 243 | |
| 244 | 244 | if ($response === null) return $events; |
@@ -401,8 +401,8 @@ discard block |
||
| 401 | 401 | * @throws \LiveStream\Exceptions\LiveStreamException |
| 402 | 402 | */ |
| 403 | 403 | public function getLiveVideo( |
| 404 | - int $accountId, |
|
| 405 | - int $eventId, |
|
| 404 | + int $accountId, |
|
| 405 | + int $eventId, |
|
| 406 | 406 | ?int $offsetPostId = null, |
| 407 | 407 | ?int $older = null, |
| 408 | 408 | ?int $newer = null |
@@ -410,9 +410,9 @@ discard block |
||
| 410 | 410 | $video = null; |
| 411 | 411 | |
| 412 | 412 | $response = $this->request("accounts/$accountId/events/$eventId/videos", 'get', null, [ |
| 413 | - 'offsetPostId' => $offsetPostId, |
|
| 414 | - 'older' => $older, |
|
| 415 | - 'newer' => $newer |
|
| 413 | + 'offsetPostId' => $offsetPostId, |
|
| 414 | + 'older' => $older, |
|
| 415 | + 'newer' => $newer |
|
| 416 | 416 | ]); |
| 417 | 417 | |
| 418 | 418 | if ($response === null) return null; |
@@ -442,9 +442,9 @@ discard block |
||
| 442 | 442 | |
| 443 | 443 | $token = $this->generateToken('playback'); |
| 444 | 444 | $query = [ |
| 445 | - 'clientId' => $this->clientId, |
|
| 446 | - 'timestamp' => $token['timestamp'], |
|
| 447 | - 'token' => $token['token'] |
|
| 445 | + 'clientId' => $this->clientId, |
|
| 446 | + 'timestamp' => $token['timestamp'], |
|
| 447 | + 'token' => $token['token'] |
|
| 448 | 448 | ]; |
| 449 | 449 | return $video->m3u8 . '?' . http_build_query($query); |
| 450 | 450 | } |
@@ -474,7 +474,7 @@ |
||
| 474 | 474 | private function refreshToken(): void |
| 475 | 475 | { |
| 476 | 476 | $now = round(microtime(true) * 1000); |
| 477 | - if (!$this->tokenTimestamp || round(($now - $this->tokenTimestamp)/1000) > 300) { |
|
| 477 | + if (!$this->tokenTimestamp || round(($now - $this->tokenTimestamp) / 1000) > 300) { |
|
| 478 | 478 | $token = $this->generateToken(); |
| 479 | 479 | $this->tokenTimestamp = $token['timestamp']; |
| 480 | 480 | $this->token = $token['token']; |
@@ -124,7 +124,9 @@ discard block |
||
| 124 | 124 | public function getAccount(int $accountId): ?Account |
| 125 | 125 | { |
| 126 | 126 | $response = $this->request("accounts/$accountId"); |
| 127 | - if ($response === null) return null; |
|
| 127 | + if ($response === null) { |
|
| 128 | + return null; |
|
| 129 | + } |
|
| 128 | 130 | |
| 129 | 131 | return Account::fromObject(json_decode($response)); |
| 130 | 132 | } |
@@ -142,7 +144,9 @@ discard block |
||
| 142 | 144 | |
| 143 | 145 | $response = $this->request("accounts/$accountId/events", 'post', $event); |
| 144 | 146 | |
| 145 | - if ($response === null) return false; |
|
| 147 | + if ($response === null) { |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 146 | 150 | |
| 147 | 151 | $event = Event::fromObject(json_decode($response)); |
| 148 | 152 | |
@@ -162,7 +166,9 @@ discard block |
||
| 162 | 166 | |
| 163 | 167 | $response = $this->request("accounts/$accountId/events/$event->id", 'put', $event); |
| 164 | 168 | |
| 165 | - if ($response === null) return false; |
|
| 169 | + if ($response === null) { |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 166 | 172 | |
| 167 | 173 | return true; |
| 168 | 174 | } |
@@ -179,7 +185,9 @@ discard block |
||
| 179 | 185 | { |
| 180 | 186 | $response = $this->request("accounts/$accountId/events/$eventId", 'delete'); |
| 181 | 187 | |
| 182 | - if ($response === null) return null; |
|
| 188 | + if ($response === null) { |
|
| 189 | + return null; |
|
| 190 | + } |
|
| 183 | 191 | |
| 184 | 192 | return Event::fromObject(json_decode($response)); |
| 185 | 193 | } |
@@ -207,7 +215,9 @@ discard block |
||
| 207 | 215 | 'logo' => new CURLFile($filePath, mime_content_type($filePath), basename($filePath)) |
| 208 | 216 | ]); |
| 209 | 217 | |
| 210 | - if ($response == null) return null; |
|
| 218 | + if ($response == null) { |
|
| 219 | + return null; |
|
| 220 | + } |
|
| 211 | 221 | |
| 212 | 222 | return Event::fromObject(json_decode($response)); |
| 213 | 223 | } |
@@ -241,7 +251,9 @@ discard block |
||
| 241 | 251 | 'order' => $order |
| 242 | 252 | ]); |
| 243 | 253 | |
| 244 | - if ($response === null) return $events; |
|
| 254 | + if ($response === null) { |
|
| 255 | + return $events; |
|
| 256 | + } |
|
| 245 | 257 | |
| 246 | 258 | foreach (json_decode($response)->data as $event) { |
| 247 | 259 | $events[] = Event::fromObject($event); |
@@ -364,7 +376,9 @@ discard block |
||
| 364 | 376 | 'saveVideo' => $saveVideo |
| 365 | 377 | ]); |
| 366 | 378 | |
| 367 | - if ($response === null) return null; |
|
| 379 | + if ($response === null) { |
|
| 380 | + return null; |
|
| 381 | + } |
|
| 368 | 382 | |
| 369 | 383 | return RTMPKey::fromObject(json_decode($response)); |
| 370 | 384 | } |
@@ -380,7 +394,9 @@ discard block |
||
| 380 | 394 | { |
| 381 | 395 | $response = $this->request("accounts/$accountId/events/$eventId/rtmp", 'put'); |
| 382 | 396 | |
| 383 | - if ($response === null) return null; |
|
| 397 | + if ($response === null) { |
|
| 398 | + return null; |
|
| 399 | + } |
|
| 384 | 400 | |
| 385 | 401 | return RTMPKey::fromObject(json_decode($response)); |
| 386 | 402 | } |
@@ -415,7 +431,9 @@ discard block |
||
| 415 | 431 | 'newer' => $newer |
| 416 | 432 | ]); |
| 417 | 433 | |
| 418 | - if ($response === null) return null; |
|
| 434 | + if ($response === null) { |
|
| 435 | + return null; |
|
| 436 | + } |
|
| 419 | 437 | |
| 420 | 438 | $response_data = json_decode($response); |
| 421 | 439 | |
@@ -438,7 +456,9 @@ discard block |
||
| 438 | 456 | * @return string|null |
| 439 | 457 | */ |
| 440 | 458 | public function getVideoHlsFileUrl(Video $video): ?string { |
| 441 | - if (!$video->m3u8) return null; |
|
| 459 | + if (!$video->m3u8) { |
|
| 460 | + return null; |
|
| 461 | + } |
|
| 442 | 462 | |
| 443 | 463 | $token = $this->generateToken('playback'); |
| 444 | 464 | $query = [ |
@@ -460,7 +480,9 @@ discard block |
||
| 460 | 480 | * @throws \LiveStream\Exceptions\LiveStreamException |
| 461 | 481 | */ |
| 462 | 482 | public function getVideoHlsFileContents(Video $video): ?string { |
| 463 | - if (!$video->m3u8) return null; |
|
| 483 | + if (!$video->m3u8) { |
|
| 484 | + return null; |
|
| 485 | + } |
|
| 464 | 486 | |
| 465 | 487 | $endpoint = substr($video->m3u8, strlen(self::BASE_URL)); |
| 466 | 488 | return $this->request($endpoint); |
@@ -521,7 +543,9 @@ discard block |
||
| 521 | 543 | ): ?string { |
| 522 | 544 | $ch = curl_init(); |
| 523 | 545 | |
| 524 | - if (!$ch) throw new Exception("Could not initialize CURL."); |
|
| 546 | + if (!$ch) { |
|
| 547 | + throw new Exception("Could not initialize CURL."); |
|
| 548 | + } |
|
| 525 | 549 | |
| 526 | 550 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 527 | 551 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
@@ -531,8 +555,7 @@ discard block |
||
| 531 | 555 | $query['timestamp'] = $this->tokenTimestamp; |
| 532 | 556 | $query['clientId'] = $this->clientId; |
| 533 | 557 | $query['token'] = $this->token; |
| 534 | - } |
|
| 535 | - else { |
|
| 558 | + } else { |
|
| 536 | 559 | curl_setopt($ch, CURLOPT_USERPWD, $this->apiKey . ':'); |
| 537 | 560 | } |
| 538 | 561 | |
@@ -543,9 +566,15 @@ discard block |
||
| 543 | 566 | ); |
| 544 | 567 | |
| 545 | 568 | if ($verb != 'get') { |
| 546 | - if ($verb == 'post') curl_setopt($ch, CURLOPT_POST, true); |
|
| 547 | - if ($verb == 'put') curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
| 548 | - if ($verb == 'delete') curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
| 569 | + if ($verb == 'post') { |
|
| 570 | + curl_setopt($ch, CURLOPT_POST, true); |
|
| 571 | + } |
|
| 572 | + if ($verb == 'put') { |
|
| 573 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
| 574 | + } |
|
| 575 | + if ($verb == 'delete') { |
|
| 576 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
| 577 | + } |
|
| 549 | 578 | if ($body) { |
| 550 | 579 | curl_setopt($ch, CURLOPT_HTTPHEADER, [ |
| 551 | 580 | 'Content-Type: ' . $body->getContentType() |
@@ -564,13 +593,21 @@ discard block |
||
| 564 | 593 | |
| 565 | 594 | curl_close($ch); |
| 566 | 595 | |
| 567 | - if ($code == 200 || $code == 201) return $response; |
|
| 596 | + if ($code == 200 || $code == 201) { |
|
| 597 | + return $response; |
|
| 598 | + } |
|
| 568 | 599 | |
| 569 | - if ($code == 404) return null; |
|
| 600 | + if ($code == 404) { |
|
| 601 | + return null; |
|
| 602 | + } |
|
| 570 | 603 | |
| 571 | - if ($code <= 199) throw new Exception("A CURL erorr with code '$code', has occurred."); |
|
| 604 | + if ($code <= 199) { |
|
| 605 | + throw new Exception("A CURL erorr with code '$code', has occurred."); |
|
| 606 | + } |
|
| 572 | 607 | |
| 573 | - if ($code == 403) throw new LiveStreamException(self::ERROR_CODES[$code] . ' ' . json_decode($response)->message); |
|
| 608 | + if ($code == 403) { |
|
| 609 | + throw new LiveStreamException(self::ERROR_CODES[$code] . ' ' . json_decode($response)->message); |
|
| 610 | + } |
|
| 574 | 611 | |
| 575 | 612 | throw new LiveStreamException(self::ERROR_CODES[$code]); |
| 576 | 613 | } |