1 | <?php |
||
12 | class Channel |
||
13 | { |
||
14 | /** |
||
15 | * The channel name. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $name; |
||
20 | |||
21 | /** |
||
22 | * The connections that got subscribed to this channel. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $connections = []; |
||
27 | |||
28 | /** |
||
29 | * Create a new instance. |
||
30 | * |
||
31 | * @param string $name |
||
32 | * @return void |
||
|
|||
33 | */ |
||
34 | public function __construct(string $name) |
||
39 | |||
40 | /** |
||
41 | * Get channel name. |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | public function getName() |
||
49 | |||
50 | /** |
||
51 | * Get the list of subscribed connections. |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | public function getConnections() |
||
59 | |||
60 | /** |
||
61 | * Check if the channel has connections. |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function hasConnections(): bool |
||
69 | |||
70 | /** |
||
71 | * Add a new connection to the channel. |
||
72 | * |
||
73 | * @see https://pusher.com/docs/pusher_protocol#presence-channel-events |
||
74 | * @param \Ratchet\ConnectionInterface $connection |
||
75 | * @param \stdClass $payload |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function subscribe(ConnectionInterface $connection, stdClass $payload): bool |
||
94 | |||
95 | /** |
||
96 | * Unsubscribe connection from the channel. |
||
97 | * |
||
98 | * @param \Ratchet\ConnectionInterface $connection |
||
99 | * @return bool |
||
100 | */ |
||
101 | public function unsubscribe(ConnectionInterface $connection): bool |
||
111 | |||
112 | /** |
||
113 | * Check if the given connection exists. |
||
114 | * |
||
115 | * @param \Ratchet\ConnectionInterface $connection |
||
116 | * @return bool |
||
117 | */ |
||
118 | public function hasConnection(ConnectionInterface $connection): bool |
||
122 | |||
123 | /** |
||
124 | * Store the connection to the subscribers list. |
||
125 | * |
||
126 | * @param \Ratchet\ConnectionInterface $connection |
||
127 | * @return void |
||
128 | */ |
||
129 | public function saveConnection(ConnectionInterface $connection) |
||
133 | |||
134 | /** |
||
135 | * Broadcast a payload to the subscribed connections. |
||
136 | * |
||
137 | * @param string|int $appId |
||
138 | * @param \stdClass $payload |
||
139 | * @param bool $replicate |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function broadcast($appId, stdClass $payload, bool $replicate = true): bool |
||
153 | |||
154 | /** |
||
155 | * Broadcast a payload to the locally-subscribed connections. |
||
156 | * |
||
157 | * @param string|int $appId |
||
158 | * @param \stdClass $payload |
||
159 | * @return bool |
||
160 | */ |
||
161 | public function broadcastLocally($appId, stdClass $payload): bool |
||
165 | |||
166 | /** |
||
167 | * Broadcast the payload, but exclude a specific socket id. |
||
168 | * |
||
169 | * @param \stdClass $payload |
||
170 | * @param string|null $socketId |
||
171 | * @param string|int $appId |
||
172 | * @param bool $replicate |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function broadcastToEveryoneExcept(stdClass $payload, ?string $socketId, $appId, bool $replicate = true) |
||
193 | |||
194 | /** |
||
195 | * Broadcast the payload, but exclude a specific socket id. |
||
196 | * |
||
197 | * @param \stdClass $payload |
||
198 | * @param string|null $socketId |
||
199 | * @param string|int $appId |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function broadcastLocallyToEveryoneExcept(stdClass $payload, ?string $socketId, $appId) |
||
208 | |||
209 | /** |
||
210 | * Check if the signature for the payload is valid. |
||
211 | * |
||
212 | * @param \Ratchet\ConnectionInterface $connection |
||
213 | * @param \stdClass $payload |
||
214 | * @return void |
||
215 | * @throws InvalidSignature |
||
216 | */ |
||
217 | protected function verifySignature(ConnectionInterface $connection, stdClass $payload) |
||
232 | } |
||
233 |
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.