From 1fb3ba8079695edd799569a0fdb0818a7c557c21 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Tue, 18 Jun 2024 16:28:57 +0200 Subject: [PATCH] Post review fixes --- examples/FileSharing.php | 21 ++++++++++--------- .../FileSharing/PublishFileMessage.php | 4 ++-- src/PubNub/Endpoints/FileSharing/SendFile.php | 6 +++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/FileSharing.php b/examples/FileSharing.php index f980092d..b855bbd4 100644 --- a/examples/FileSharing.php +++ b/examples/FileSharing.php @@ -16,20 +16,21 @@ $pubnub = new PubNub($config); // Sending file -// $fileHandle = fopen(__DIR__ . DIRECTORY_SEPARATOR . $fileName, "r"); -// $sendFileResult = $pubnub->sendFile() -// ->channel($channelName) -// ->fileName($fileName) -// ->message("Hello from PHP SDK") -// ->fileHandle($fileHandle) -// ->sync(); +$fileHandle = fopen(__DIR__ . DIRECTORY_SEPARATOR . $fileName, "r"); +$sendFileResult = $pubnub->sendFile() + ->channel($channelName) + ->fileName($fileName) + ->message("Hello from PHP SDK") + ->fileHandle($fileHandle) + ->sync(); -// fclose($fileHandle); +fclose($fileHandle); // Listing files in the channel $channelFiles = $pubnub->listFiles()->channel($channelName)->sync(); -if ($channelFiles->getCount() > 0) { - print("There are {$channelFiles->getCount()} files in the channel {$channelName}\n"); +$fileCount = $channelFiles->getCount(); +if ($fileCount > 0) { + print("There are {$fileCount} files in the channel {$channelName}\n"); foreach ($channelFiles->getFiles() as $idx => $file) { print("File[{$idx}]: {$file->getName()} with ID: {$file->getId()}," . "size {$file->getSize()}, created at: {$file->getCreationTime()}\n"); diff --git a/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php b/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php index abc9f806..34ce9584 100644 --- a/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php +++ b/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php @@ -65,7 +65,7 @@ public function encryptMessage($message) protected function buildMessage() { - $message = [ + $messageData = [ "message" => $this->message, "file" => [ "id" => $this->fileId, @@ -73,7 +73,7 @@ protected function buildMessage() ] ]; - return $this->encryptMessage($message); + return $this->encryptMessage($messageData); } protected function customParams() diff --git a/src/PubNub/Endpoints/FileSharing/SendFile.php b/src/PubNub/Endpoints/FileSharing/SendFile.php index 89ea22fc..02ee6b43 100644 --- a/src/PubNub/Endpoints/FileSharing/SendFile.php +++ b/src/PubNub/Endpoints/FileSharing/SendFile.php @@ -266,13 +266,13 @@ public function sync() if (isset($this->meta)) { $publishRequest->meta($this->meta); } - if (isset($this->meta)) { + if (isset($this->message)) { $publishRequest->message($this->message); } - if (isset($this->meta)) { + if (isset($this->shouldStore)) { $publishRequest->shouldStore($this->shouldStore); } - if (isset($this->meta)) { + if (isset($this->ttl)) { $publishRequest->ttl($this->ttl); }