1 | <?php |
||
33 | class WebSocketServer |
||
34 | { |
||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | private $port; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $host; |
||
44 | |||
45 | /** |
||
46 | * @var ServerHandshake |
||
47 | */ |
||
48 | private $handshake; |
||
49 | |||
50 | /** |
||
51 | * @var MessageHandlerInterface[] |
||
52 | */ |
||
53 | private $messageHandlers; |
||
54 | |||
55 | /** |
||
56 | * @var Connection[] |
||
57 | */ |
||
58 | private $connections; |
||
59 | |||
60 | /** |
||
61 | * @var LoopInterface |
||
62 | */ |
||
63 | private $loop; |
||
64 | |||
65 | /** |
||
66 | * @var ServerInterface |
||
67 | */ |
||
68 | private $server; |
||
69 | |||
70 | /** |
||
71 | * @var MessageProcessor |
||
72 | */ |
||
73 | private $messageProcessor; |
||
74 | |||
75 | /** |
||
76 | * @var array |
||
77 | */ |
||
78 | private $config; |
||
79 | |||
80 | /** |
||
81 | * @var LoggerInterface |
||
82 | */ |
||
83 | private $logger; |
||
84 | |||
85 | /** |
||
86 | * @var CloseEventDescriptor |
||
87 | */ |
||
88 | private $statusCodeDescriptor; |
||
89 | |||
90 | /** |
||
91 | * @param int $port The number of the port to bind |
||
92 | * @param string $host The host to listen on (by default 127.0.0.1) |
||
93 | * @param array $config |
||
94 | */ |
||
95 | public function __construct($port, $host = '127.0.0.1', $config = []) |
||
108 | |||
109 | /** |
||
110 | * @param MessageHandlerInterface|string $messageHandler An instance of a class as string |
||
111 | * @param string $uri The URI you want to bind on |
||
112 | */ |
||
113 | public function setMessageHandler($messageHandler, $uri = '*') |
||
130 | |||
131 | /** |
||
132 | * Launch the WebSocket server and an infinite loop that act on event. |
||
133 | * |
||
134 | * @throws \Exception |
||
135 | */ |
||
136 | public function start() |
||
161 | |||
162 | /** |
||
163 | * @param ConnectionInterface $socketStream |
||
164 | */ |
||
165 | private function onNewConnection(ConnectionInterface $socketStream) |
||
179 | |||
180 | /** |
||
181 | * |
||
182 | * @param Connection $connection |
||
183 | */ |
||
184 | private function onDisconnect(Connection $connection) |
||
191 | |||
192 | /** |
||
193 | * Remove a Connection instance by his object id |
||
194 | * @param Connection $connection |
||
195 | * @param bool $strict Define if the process should stop if unfindable |
||
196 | * @throws RuntimeException This method throw an exception if the $connection instance object isn't findable in websocket server's connections |
||
197 | */ |
||
198 | private function removeConnection(Connection $connection, bool $strict = true) |
||
213 | |||
214 | /** |
||
215 | * @param string $uri |
||
216 | * @param Connection $connection |
||
217 | * @return MessageHandlerInterface|null |
||
218 | */ |
||
219 | private function getMessageHandler(string $uri, Connection $connection) |
||
242 | |||
243 | /** |
||
244 | * Build the message processor with configuration |
||
245 | */ |
||
246 | private function buildMessageProcessor() |
||
264 | |||
265 | /** |
||
266 | * Sets the configuration |
||
267 | * |
||
268 | * @param array $config |
||
269 | * @throws ConfigException |
||
270 | */ |
||
271 | private function setConfig(array $config) |
||
288 | |||
289 | /** |
||
290 | * @return SimpleLogger|LoggerInterface |
||
291 | */ |
||
292 | public function getLogger() |
||
300 | |||
301 | /** |
||
302 | * Allows you to set a custom logger |
||
303 | * |
||
304 | * @param LoggerInterface $logger |
||
305 | * @return WebSocketServer |
||
306 | */ |
||
307 | public function setLogger(LoggerInterface $logger) |
||
313 | |||
314 | /** |
||
315 | * Allows to specify a loop that will be used instead of the reactphp generated loop. |
||
316 | * |
||
317 | * @param LoopInterface $loop |
||
318 | * @return WebSocketServer |
||
319 | */ |
||
320 | public function setLoop(LoopInterface $loop) |
||
326 | |||
327 | /** |
||
328 | * @param ServerInterface $server |
||
329 | * @return WebSocketServer |
||
330 | */ |
||
331 | public function setSocketServer(ServerInterface $server) |
||
337 | } |
||
338 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.