1 | <?php |
||
9 | trait PresencelyChannelable |
||
10 | { |
||
11 | /** |
||
12 | * Data for the users connected to this channel. |
||
13 | * |
||
14 | * Note: If replication is enabled, this will only contain entries |
||
15 | * for the users directly connected to this server instance. Requests |
||
16 | * for data for all users in the channel should be routed through |
||
17 | * ReplicationInterface. |
||
18 | * |
||
19 | * @var string[] |
||
20 | */ |
||
21 | protected $users = []; |
||
22 | |||
23 | /** |
||
24 | * Get the members in the presence channel. |
||
25 | * |
||
26 | * @param string $appId |
||
27 | * @return PromiseInterface |
||
28 | */ |
||
29 | public function getUsers($appId) |
||
33 | |||
34 | /** |
||
35 | * Subscribe the connection to the channel. |
||
36 | * |
||
37 | * @param ConnectionInterface $connection |
||
38 | * @param stdClass $payload |
||
39 | * @return void |
||
40 | * @throws InvalidSignature |
||
41 | * @see https://pusher.com/docs/pusher_protocol#presence-channel-events |
||
42 | */ |
||
43 | public function subscribe(ConnectionInterface $connection, stdClass $payload) |
||
78 | |||
79 | /** |
||
80 | * Unsubscribe the connection from the Presence channel. |
||
81 | * |
||
82 | * @param ConnectionInterface $connection |
||
83 | * @return void |
||
84 | */ |
||
85 | public function unsubscribe(ConnectionInterface $connection) |
||
111 | |||
112 | /** |
||
113 | * Get the Presence Channel to array. |
||
114 | * |
||
115 | * @param string|null $appId |
||
116 | * @return PromiseInterface |
||
117 | */ |
||
118 | public function toArray($appId = null) |
||
128 | |||
129 | /** |
||
130 | * Get the Presence channel data. |
||
131 | * |
||
132 | * @param array $users |
||
133 | * @return array |
||
134 | */ |
||
135 | protected function getChannelData(array $users): array |
||
145 | |||
146 | /** |
||
147 | * Get the Presence Channel's users. |
||
148 | * |
||
149 | * @param array $users |
||
150 | * @return array |
||
151 | */ |
||
152 | protected function getUserIds(array $users): array |
||
160 | |||
161 | /** |
||
162 | * Compute the hash for the presence channel integrity. |
||
163 | * |
||
164 | * @param array $users |
||
165 | * @return array |
||
166 | */ |
||
167 | protected function getHash(array $users): array |
||
177 | } |
||
178 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: