|
7 | 7 | use PubNub\PNConfiguration; |
8 | 8 | use PubNub\PubNub; |
9 | 9 | use PubNub\CryptoModule; |
| 10 | +use PubNub\Crypto\AesCbcCryptor; |
| 11 | +use PubNub\Crypto\LegacyCryptor; |
10 | 12 | use PubNub\Enums\PNStatusCategory; |
11 | 13 | use PubNub\Callbacks\SubscribeCallback; |
| 14 | +use PubNub\PubNubCrypto; |
| 15 | +use PubNub\PubNubCryptoLegacy; |
12 | 16 |
|
13 | 17 | // snippet.setup |
14 | 18 | // Create a new configuration instance |
@@ -202,6 +206,103 @@ function presence($pubnub, $presence) |
202 | 206 | $pubnub = new PubNub($pnconf); |
203 | 207 | // snippet.end |
204 | 208 |
|
| 209 | +// snippet.init_non_secure |
| 210 | +$pnConfiguration = new PNConfiguration(); |
| 211 | + |
| 212 | +$pnConfiguration->setSubscribeKey("my_sub_key"); |
| 213 | +$pnConfiguration->setPublishKey("my_pub_key"); |
| 214 | +$pnConfiguration->setSecure(false); |
| 215 | +$pnConfiguration->setUserId("myUniqueUserId"); |
| 216 | +$pubnub = new PubNub($pnConfiguration); |
| 217 | +// snippet.end |
| 218 | + |
| 219 | +// snippet.init_read_only |
| 220 | +$pnConfiguration = new PNConfiguration(); |
| 221 | + |
| 222 | +$pnConfiguration->setUserId("myUniqueUserId"); |
| 223 | +$pnConfiguration->setSubscribeKey("my_sub_key"); |
| 224 | + |
| 225 | +$pubnub = new PubNub($pnConfiguration); |
| 226 | +// snippet.end |
| 227 | + |
| 228 | +// snippet.use_custom_uuid |
| 229 | +$pnconf = new PNConfiguration(); |
| 230 | + |
| 231 | +$pnconf->setSubscribeKey("mySubscribeKey"); |
| 232 | +$pnconf->setPublishKey("myPublishKey"); |
| 233 | +$pnconf->setUserId("myUniqueUserId"); |
| 234 | + |
| 235 | +$pubnub = new PubNub($pnconf); |
| 236 | +// snippet.end |
| 237 | + |
| 238 | +// snippet.remove_listeners |
| 239 | +$subscribeCallback = new MySubscribeCallback(); |
| 240 | + |
| 241 | +$pubnub->addListener($subscribeCallback); |
| 242 | + |
| 243 | +// some time later |
| 244 | +$pubnub->removeListener($subscribeCallback); |
| 245 | +// snippet.end |
| 246 | + |
| 247 | +// snippet.set_user_id |
| 248 | +$pnconf = new PNConfiguration(); |
| 249 | +$pnconf->setUserId("myUniqueUserId"); |
| 250 | +// snippet.end |
| 251 | + |
| 252 | +// snippet.get_user_id |
| 253 | +$pubnub->getConfiguration() |
| 254 | + ->getUserId(); |
| 255 | +// snippet.end |
| 256 | + |
| 257 | +// snippet.set_auth_key |
| 258 | +$pubnub->getConfiguration() |
| 259 | + ->setAuthKey("my_newauthkey"); |
| 260 | +// snippet.end |
| 261 | + |
| 262 | +// snippet.get_auth_key |
| 263 | +$pubnub->getConfiguration() |
| 264 | + ->getAuthKey(); |
| 265 | +// snippet.end |
| 266 | + |
| 267 | +// snippet.get_filter_expression |
| 268 | +$pubnub->getConfiguration()->getFilterExpression(); |
| 269 | +// snippet.end |
| 270 | + |
| 271 | +// snippet.disable_immutable_check |
| 272 | +$config = new PNConfiguration(); |
| 273 | +$config->setPublishKey('demo'); |
| 274 | +$config->setSubscribeKey('demo'); |
| 275 | +$config->setUserId('demo'); |
| 276 | +// not recommended, disables config immutability |
| 277 | +$config->disableImmutableCheck(); |
| 278 | + |
| 279 | +$pn = new PubNub($config); |
| 280 | +// snippet.end |
| 281 | + |
| 282 | +// snippet.crypto_module_setup |
| 283 | +// encrypts using 256-bit AES-CBC cipher (recommended) |
| 284 | +// decrypts data encrypted with the legacy and the 256-bit AES-CBC ciphers |
| 285 | +$pnConfiguration = new PNConfiguration(); |
| 286 | +$pnConfiguration->setSubscribeKey('demo'); |
| 287 | +$pnConfiguration->setPublishKey('demo'); |
| 288 | +$pnConfiguration->setUserId('crypto-demo'); |
| 289 | +$cryptoModule = CryptoModule::aesCbcCryptor("enigma", true); |
| 290 | +$pnConfiguration->setCryptoModule($cryptoModule); |
| 291 | + |
| 292 | +$pubnub = new PubNub($pnConfiguration); |
| 293 | + |
| 294 | +// encrypts with 128-bit cipher key entropy(legacy) |
| 295 | +// decrypts data encrypted with the legacy and the 256-bit AES-CBC ciphers |
| 296 | +$pnConfiguration2 = new PNConfiguration(); |
| 297 | +$pnConfiguration2->setSubscribeKey('demo'); |
| 298 | +$pnConfiguration2->setPublishKey('demo'); |
| 299 | +$pnConfiguration2->setUserId('crypto-demo-legacy'); |
| 300 | +$legacyCryptoModule = CryptoModule::legacyCryptor("enigma", true); |
| 301 | +$pnConfiguration2->setCryptoModule($legacyCryptoModule); |
| 302 | + |
| 303 | +$pubnub2 = new PubNub($pnConfiguration2); |
| 304 | +// snippet.end |
| 305 | + |
205 | 306 | // Verify configuration |
206 | 307 | assert($pnconf->getSubscribeKey() === (getenv('SUBSCRIBE_KEY') ?: 'demo')); |
207 | 308 | assert($pnconf->getUserId() === "filter-demo-user"); |
|
0 commit comments