芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/bit-alphas-ltd.com/user/project/vendor/vonage/client-core/src/Call/Stream.php
id = $id; } /** * @throws ClientExceptionInterface * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server * * @return $this|Event */ public function __invoke(?Stream $stream = null) { if (is_null($stream)) { return $this; } return $this->put($stream); } public function getId(): ?string { return $this->id; } public function setUrl($url): void { if (!is_array($url)) { $url = [$url]; } $this->data['stream_url'] = $url; } /** * @param string|int $times */ public function setLoop($times): void { $this->data['loop'] = (int)$times; } /** * @param null|mixed $stream * * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server * @throws ClientExceptionInterface */ public function put($stream = null): Event { if (!$stream) { $stream = $this; } $request = new Request( $this->getClient()->getApiUrl() . Collection::getCollectionPath() . '/' . $this->getId() . '/stream', 'PUT', 'php://temp', ['content-type' => 'application/json'] ); $request->getBody()->write(json_encode($stream)); $response = $this->client->send($request); return $this->parseEventResponse($response); } /** * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server * @throws ClientExceptionInterface */ public function delete(): Event { $request = new Request( $this->getClient()->getApiUrl() . Collection::getCollectionPath() . '/' . $this->getId() . '/stream', 'DELETE' ); $response = $this->client->send($request); return $this->parseEventResponse($response); } /** * @throws ClientException\Exception * @throws ClientException\Request * @throws ClientException\Server */ protected function parseEventResponse(ResponseInterface $response): Event { if ((int)$response->getStatusCode() !== 200) { throw $this->getException($response); } $json = json_decode($response->getBody()->getContents(), true); if (!$json) { throw new ClientException\Exception('Unexpected Response Body Format'); } return new Event($json); } /** * @throws ClientException\Exception */ protected function getException(ResponseInterface $response) { $body = json_decode($response->getBody()->getContents(), true); $status = $response->getStatusCode(); if ($status >= 400 && $status < 500) { $e = new ClientException\Request($body['error_title'], $status); } elseif ($status >= 500 && $status < 600) { $e = new ClientException\Server($body['error_title'], $status); } else { $e = new ClientException\Exception('Unexpected HTTP Status Code'); throw $e; } return $e; } public function jsonSerialize(): array { return $this->data; } }