1 | <?php |
||
10 | trait PresencelyChannelable |
||
11 | { |
||
12 | /** |
||
13 | * Data for the users connected to this channel. |
||
14 | * |
||
15 | * Note: If replication is enabled, this will only contain entries |
||
16 | * for the users directly connected to this server instance. Requests |
||
17 | * for data for all users in the channel should be routed through |
||
18 | * ReplicationInterface. |
||
19 | * |
||
20 | * @var string[] |
||
21 | */ |
||
22 | protected $users = []; |
||
23 | |||
24 | /** |
||
25 | * Get the members in the presence channel. |
||
26 | * |
||
27 | * @param string $appId |
||
28 | * @return PromiseInterface |
||
29 | */ |
||
30 | public function getUsers($appId) |
||
34 | |||
35 | /** |
||
36 | * Subscribe the connection to the channel. |
||
37 | * |
||
38 | * @param ConnectionInterface $connection |
||
39 | * @param stdClass $payload |
||
40 | * @return void |
||
41 | * @throws InvalidSignature |
||
42 | * @see https://pusher.com/docs/pusher_protocol#presence-channel-events |
||
43 | */ |
||
44 | public function subscribe(ConnectionInterface $connection, stdClass $payload) |
||
79 | |||
80 | /** |
||
81 | * Unsubscribe the connection from the Presence channel. |
||
82 | * |
||
83 | * @param ConnectionInterface $connection |
||
84 | * @return void |
||
85 | */ |
||
86 | public function unsubscribe(ConnectionInterface $connection) |
||
112 | |||
113 | /** |
||
114 | * Get the Presence Channel to array. |
||
115 | * |
||
116 | * @param string|null $appId |
||
117 | * @return PromiseInterface |
||
118 | */ |
||
119 | public function toArray($appId = null) |
||
129 | |||
130 | /** |
||
131 | * Get the Presence channel data. |
||
132 | * |
||
133 | * @param array $users |
||
134 | * @return array |
||
135 | */ |
||
136 | protected function getChannelData(array $users): array |
||
146 | |||
147 | /** |
||
148 | * Get the Presence Channel's users. |
||
149 | * |
||
150 | * @param array $users |
||
151 | * @return array |
||
152 | */ |
||
153 | protected function getUserIds(array $users): array |
||
161 | |||
162 | /** |
||
163 | * Compute the hash for the presence channel integrity. |
||
164 | * |
||
165 | * @param array $users |
||
166 | * @return array |
||
167 | */ |
||
168 | protected function getHash(array $users): array |
||
178 | } |
||
179 |
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: