1 | <?php |
||
32 | class WebSocketServer |
||
33 | { |
||
34 | /** |
||
35 | * @var int |
||
36 | */ |
||
37 | private $port; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $host; |
||
43 | |||
44 | /** |
||
45 | * @var ServerHandshake |
||
46 | */ |
||
47 | private $handshake; |
||
48 | |||
49 | /** |
||
50 | * @var MessageHandlerInterface[] |
||
51 | */ |
||
52 | private $messageHandlers; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | private $connections; |
||
58 | |||
59 | /** |
||
60 | * @var LoopInterface |
||
61 | */ |
||
62 | private $loop; |
||
63 | |||
64 | /** |
||
65 | * @var ServerInterface |
||
66 | */ |
||
67 | private $server; |
||
68 | |||
69 | /** |
||
70 | * @var MessageProcessor |
||
71 | */ |
||
72 | private $messageProcessor; |
||
73 | |||
74 | /** |
||
75 | * @var array |
||
76 | */ |
||
77 | private $config; |
||
78 | |||
79 | /** |
||
80 | * @var LoggerInterface |
||
81 | */ |
||
82 | private $logger; |
||
83 | |||
84 | /** |
||
85 | * @param int $port The number of the port to bind |
||
86 | * @param string $host The host to listen on (by default 127.0.0.1) |
||
87 | * @param array $config |
||
88 | */ |
||
89 | 8 | public function __construct($port, $host = '127.0.0.1', $config = []) |
|
102 | |||
103 | /** |
||
104 | * @param MessageHandlerInterface|string $messageHandler An instance of a class as string |
||
105 | * @param string $uri The URI you want to bind on |
||
106 | */ |
||
107 | 4 | public function setMessageHandler($messageHandler, $uri = '*') |
|
124 | |||
125 | /** |
||
126 | * Launch the WebSocket server and an infinite loop that act on event. |
||
127 | * |
||
128 | * @throws \Exception |
||
129 | */ |
||
130 | 4 | public function start() |
|
155 | |||
156 | /** |
||
157 | * @param ConnectionInterface $socketStream |
||
158 | */ |
||
159 | private function onNewConnection(ConnectionInterface $socketStream) |
||
168 | |||
169 | /** |
||
170 | * @param string $uri |
||
171 | * @param Connection $connection |
||
172 | * @return MessageHandlerInterface|null |
||
173 | */ |
||
174 | 4 | private function getMessageHandler(string $uri, Connection $connection) |
|
197 | |||
198 | /** |
||
199 | * Build the message processor with configuration |
||
200 | */ |
||
201 | 7 | private function buildMessageProcessor() |
|
219 | |||
220 | /** |
||
221 | * Sets the configuration |
||
222 | * |
||
223 | * @param array $config |
||
224 | * @throws ConfigException |
||
225 | */ |
||
226 | 8 | private function setConfig(array $config) |
|
243 | |||
244 | /** |
||
245 | * @return SimpleLogger|LoggerInterface |
||
246 | */ |
||
247 | 4 | public function getLogger() |
|
255 | |||
256 | /** |
||
257 | * Allows you to set a custom logger |
||
258 | * |
||
259 | * @param LoggerInterface $logger |
||
260 | * @return WebSocketServer |
||
261 | */ |
||
262 | 1 | public function setLogger(LoggerInterface $logger) |
|
268 | |||
269 | /** |
||
270 | * Allows to specify a loop that will be used instead of the reactphp generated loop. |
||
271 | * |
||
272 | * @param LoopInterface $loop |
||
273 | * @return WebSocketServer |
||
274 | */ |
||
275 | 4 | public function setLoop(LoopInterface $loop) |
|
281 | |||
282 | /** |
||
283 | * @param ServerInterface $server |
||
284 | * @return WebSocketServer |
||
285 | */ |
||
286 | 4 | public function setSocketServer(ServerInterface $server) |
|
292 | } |
||
293 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.