1 | <?php |
||
12 | trait Channelable |
||
13 | { |
||
14 | /** |
||
15 | * The channel name. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $channelName; |
||
20 | |||
21 | /** |
||
22 | * The replicator client. |
||
23 | * |
||
24 | * @var ReplicationInterface |
||
25 | */ |
||
26 | protected $replicator; |
||
27 | |||
28 | /** |
||
29 | * The connections that got subscribed. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $subscribedConnections = []; |
||
34 | |||
35 | /** |
||
36 | * Create a new instance. |
||
37 | * |
||
38 | * @param string $channelName |
||
39 | * @return void |
||
|
|||
40 | */ |
||
41 | public function __construct(string $channelName) |
||
46 | |||
47 | /** |
||
48 | * Get the channel name. |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | public function getChannelName(): string |
||
56 | |||
57 | /** |
||
58 | * Check if the channel has connections. |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function hasConnections(): bool |
||
66 | |||
67 | /** |
||
68 | * Get all subscribed connections. |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | public function getSubscribedConnections(): array |
||
76 | |||
77 | /** |
||
78 | * Check if the signature for the payload is valid. |
||
79 | * |
||
80 | * @param \Ratchet\ConnectionInterface $connection |
||
81 | * @param \stdClass $payload |
||
82 | * @return void |
||
83 | * @throws InvalidSignature |
||
84 | */ |
||
85 | protected function verifySignature(ConnectionInterface $connection, stdClass $payload) |
||
100 | |||
101 | /** |
||
102 | * Subscribe to the channel. |
||
103 | * |
||
104 | * @see https://pusher.com/docs/pusher_protocol#presence-channel-events |
||
105 | * @param \Ratchet\ConnectionInterface $connection |
||
106 | * @param \stdClass $payload |
||
107 | * @return void |
||
108 | */ |
||
109 | public function subscribe(ConnectionInterface $connection, stdClass $payload) |
||
120 | |||
121 | /** |
||
122 | * Unsubscribe connection from the channel. |
||
123 | * |
||
124 | * @param \Ratchet\ConnectionInterface $connection |
||
125 | * @return void |
||
126 | */ |
||
127 | public function unsubscribe(ConnectionInterface $connection) |
||
140 | |||
141 | /** |
||
142 | * Store the connection to the subscribers list. |
||
143 | * |
||
144 | * @param \Ratchet\ConnectionInterface $connection |
||
145 | * @return void |
||
146 | */ |
||
147 | protected function saveConnection(ConnectionInterface $connection) |
||
164 | |||
165 | /** |
||
166 | * Broadcast a payload to the subscribed connections. |
||
167 | * |
||
168 | * @param \stdClass $payload |
||
169 | * @return void |
||
170 | */ |
||
171 | public function broadcast($payload) |
||
177 | |||
178 | /** |
||
179 | * Broadcast the payload, but exclude the current connection. |
||
180 | * |
||
181 | * @param \Ratchet\ConnectionInterface $connection |
||
182 | * @param \stdClass $payload |
||
183 | * @return void |
||
184 | */ |
||
185 | public function broadcastToOthers(ConnectionInterface $connection, stdClass $payload) |
||
191 | |||
192 | /** |
||
193 | * Broadcast the payload, but exclude a specific socket id. |
||
194 | * |
||
195 | * @param \stdClass $payload |
||
196 | * @param string|null $socketId |
||
197 | * @param mixed $appId |
||
198 | * @param bool $publish |
||
199 | * @return void |
||
200 | */ |
||
201 | public function broadcastToEveryoneExcept(stdClass $payload, ?string $socketId, $appId, bool $publish = true) |
||
226 | |||
227 | /** |
||
228 | * Convert the channel to array. |
||
229 | * |
||
230 | * @param mixed $appId |
||
231 | * @return array |
||
232 | */ |
||
233 | public function toArray($appId = null) |
||
240 | } |
||
241 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.