|
1 | 1 | <?php |
| 2 | +// snippet.hide |
| 3 | +// Ignoring example because of the "no side effects" rule |
| 4 | +// phpcs:ignoreFile |
| 5 | +// snippet.show |
2 | 6 |
|
3 | 7 | // This file contains code snippets for the Getting Started guide |
4 | 8 | // Include Composer autoloader (adjust path if needed) |
|
35 | 39 | // snippet.end |
36 | 40 |
|
37 | 41 | // snippet.event_listeners |
38 | | -class MySubscribeCallback extends SubscribeCallback { |
39 | | - function status($pubnub, $status) { |
| 42 | +class MySubscribeCallback extends SubscribeCallback |
| 43 | +{ |
| 44 | + public function status($pubnub, $status) |
| 45 | + { |
40 | 46 | if ($status->getCategory() === PNStatusCategory::PNUnexpectedDisconnectCategory) { |
41 | 47 | // This event happens when radio / connectivity is lost |
42 | 48 | echo "Unexpected disconnect - network may be down" . PHP_EOL; |
43 | | - } else if ($status->getCategory() === PNStatusCategory::PNConnectedCategory) { |
| 49 | + } elseif ($status->getCategory() === PNStatusCategory::PNConnectedCategory) { |
44 | 50 | // Connect event. You can do stuff like publish, and know you'll get it |
45 | 51 | echo "Connected to PubNub!" . PHP_EOL; |
46 | | - } else if ($status->getCategory() === PNStatusCategory::PNDecryptionErrorCategory) { |
| 52 | + } elseif ($status->getCategory() === PNStatusCategory::PNDecryptionErrorCategory) { |
47 | 53 | // Handle message decryption error |
48 | 54 | echo "Decryption error: " . $status->getException() . PHP_EOL; |
49 | 55 | } |
50 | | - } |
| 56 | + } |
51 | 57 |
|
52 | | - function message($pubnub, $message) { |
| 58 | + public function message($pubnub, $message) |
| 59 | + { |
53 | 60 | // Handle new message stored in message.message |
54 | 61 | echo "Received message: " . json_encode($message->getMessage()) . PHP_EOL; |
55 | 62 | echo "Publisher: " . $message->getPublisher() . PHP_EOL; |
56 | 63 | echo "Channel: " . $message->getChannel() . PHP_EOL; |
57 | 64 | echo "Timetoken: " . $message->getTimetoken() . PHP_EOL; |
58 | 65 | } |
59 | 66 |
|
60 | | - function presence($pubnub, $presence) { |
| 67 | + public function presence($pubnub, $presence) |
| 68 | + { |
61 | 69 | // Handle incoming presence data |
62 | 70 | echo "Presence event: " . $presence->getEvent() . PHP_EOL; |
63 | 71 | echo "UUID: " . $presence->getUuid() . PHP_EOL; |
@@ -131,4 +139,3 @@ function presence($pubnub, $presence) { |
131 | 139 | echo "Error: " . $exception->getMessage() . PHP_EOL; |
132 | 140 | } |
133 | 141 | // snippet.end |
134 | | - |
|
0 commit comments