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 void |
||
77 | */ |
||
78 | public function subscribe(ConnectionInterface $connection, stdClass $payload) |
||
92 | |||
93 | /** |
||
94 | * Unsubscribe connection from the channel. |
||
95 | * |
||
96 | * @param \Ratchet\ConnectionInterface $connection |
||
97 | * @return void |
||
98 | */ |
||
99 | public function unsubscribe(ConnectionInterface $connection) |
||
107 | |||
108 | /** |
||
109 | * Store the connection to the subscribers list. |
||
110 | * |
||
111 | * @param \Ratchet\ConnectionInterface $connection |
||
112 | * @return void |
||
113 | */ |
||
114 | protected function saveConnection(ConnectionInterface $connection) |
||
118 | |||
119 | /** |
||
120 | * Broadcast a payload to the subscribed connections. |
||
121 | * |
||
122 | * @param string|int $appId |
||
123 | * @param \stdClass $payload |
||
124 | * @param bool $replicate |
||
125 | * @return bool |
||
126 | */ |
||
127 | public function broadcast($appId, stdClass $payload, bool $replicate = true): bool |
||
138 | |||
139 | /** |
||
140 | * Broadcast the payload, but exclude a specific socket id. |
||
141 | * |
||
142 | * @param \stdClass $payload |
||
143 | * @param string|null $socketId |
||
144 | * @param string|int $appId |
||
145 | * @param bool $replicate |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function broadcastToEveryoneExcept(stdClass $payload, ?string $socketId, $appId, bool $replicate = true) |
||
166 | |||
167 | /** |
||
168 | * Check if the signature for the payload is valid. |
||
169 | * |
||
170 | * @param \Ratchet\ConnectionInterface $connection |
||
171 | * @param \stdClass $payload |
||
172 | * @return void |
||
173 | * @throws InvalidSignature |
||
174 | */ |
||
175 | protected function verifySignature(ConnectionInterface $connection, stdClass $payload) |
||
190 | } |
||
191 |
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.