Add write protection with examples and tests#115
Conversation
| $description = trim(fgets(STDIN)); | ||
|
|
||
| // Set channel metadata | ||
| $pubnub->setChannelMetadata() |
There was a problem hiding this comment.
I am wondering how useful this can be for SDK user.
? What do you think about following approach:
<?php
set_time_limit(0);
require('../../vendor/autoload.php');
use PubNub\PNConfiguration;
use PubNub\PubNub;
$pnconf = new PNConfiguration();
$pnconf->setPublishKey("demo");
$pnconf->setSubscribeKey("demo");
$pnconf->setUuid("example");
$pubnub = new PubNub($pnconf);
$channel = "demo_example";
$channelName = "Channel1on1";
$channelDescription = "Channel for 1on1 conversation";
$status = "active";
$type = "1on1";
$initialCustom = ["Days" => "Mon-Fri"];
// Set initial channel metadata
$pubnub->setChannelMetadata()
->channel($channel)
->name($channelName)
->description($channelDescription)
->meta(["custom" => $initialCustom])
->status($status)
->type($type)
->sync();
// Fetch the current metadata
$response = $pubnub->getChannelMetadata()
->channel($channel)
->includeCustom(true)
->sync();
$custom = (array)$response->getCustom();
$additionalMetadata = ["Months" => "Jan-May"];
// Merge additional metadata
$updatedCustomMetadata = array_merge($custom, $additionalMetadata);
// Update the channel metadata
$updatedMetadata = $pubnub->setChannelMetadata()
->channel($channel)
->custom($updatedCustomMetadata)
->includeCustom(true)
->sync();
print("Updated channel metadata:");
print_r($updatedMetadata->getData());
// Cleanup
$pubnub->removeChannelMetadata()
->channel($channel)
->sync();
There was a problem hiding this comment.
I'll add it in a different PR because it seems that this SDK misses some features and I have to look into it
| * @param string $prev | ||
| * @param string $next | ||
| * @param array $data | ||
| * @param $string $eTag |
There was a problem hiding this comment.
What about:
@param ?string $eTag
?
| if (!empty($data)) | ||
| { | ||
| $data_string = json_encode($data); | ||
| if (!empty($data)) { |
There was a problem hiding this comment.
Shouldn't be:
if (!empty($this->data)) {
$data_string = json_encode($this->data);
} else {
$data_string = 'null';
}
|
|
||
| foreach($payload["data"] as $value) | ||
| { | ||
| foreach ($payload["data"] as $value) { |
There was a problem hiding this comment.
Is this possible that data is null here?
If so array_push may fail?
There was a problem hiding this comment.
no problem with that because on line 120 I create an empty array for data and if the $payload is not iterable. the worst thing may be an warning about undefined key, but I guess somewhere higher the key is always defined at least as null
|
@pubnub-release-bot release |
|
🚀 Release successfully completed 🚀 |
feat: Write protection with If-Match eTag header
Write protection with If-Match eTag header for setting channel and uuid metadata