@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param resource $resource |
47 | 47 | * @param WebSocketServer $server |
48 | 48 | */ |
49 | - public function __construct ($resource, WebSocketServer $server) { |
|
49 | + public function __construct($resource, WebSocketServer $server) { |
|
50 | 50 | parent::__construct($resource); |
51 | 51 | $this->server = $server; |
52 | 52 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param string $reason |
70 | 70 | * @return $this |
71 | 71 | */ |
72 | - public function close (int $code = null, string $reason = '') { |
|
72 | + public function close(int $code = null, string $reason = '') { |
|
73 | 73 | try { |
74 | 74 | if ($code >= 1000 and $this->state === self::STATE_OK) { |
75 | 75 | $this->getFrameHandler()->writeClose($code, $reason); |
@@ -86,42 +86,42 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * @return FrameHandler |
88 | 88 | */ |
89 | - public function getFrameHandler (): FrameHandler { |
|
89 | + public function getFrameHandler(): FrameHandler { |
|
90 | 90 | return $this->frameHandler ?? $this->frameHandler = new FrameHandler($this); |
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @return FrameReader |
95 | 95 | */ |
96 | - public function getFrameReader (): FrameReader { |
|
96 | + public function getFrameReader(): FrameReader { |
|
97 | 97 | return $this->frameReader ?? $this->frameReader = new FrameReader($this); |
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @return HandShake |
102 | 102 | */ |
103 | - public function getHandshake (): HandShake { |
|
103 | + public function getHandshake(): HandShake { |
|
104 | 104 | return $this->handshake ?? $this->handshake = new HandShake($this); |
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @return WebSocketServer |
109 | 109 | */ |
110 | - public function getServer (): WebSocketServer { |
|
110 | + public function getServer(): WebSocketServer { |
|
111 | 111 | return $this->server; |
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @return int |
116 | 116 | */ |
117 | - public function getState (): int { |
|
117 | + public function getState(): int { |
|
118 | 118 | return $this->state; |
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | 122 | * @return bool |
123 | 123 | */ |
124 | - final public function isOk (): bool { |
|
124 | + final public function isOk(): bool { |
|
125 | 125 | return $this->state === self::STATE_OK; |
126 | 126 | } |
127 | 127 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @param string $binary |
132 | 132 | */ |
133 | - public function onBinary (string $binary): void { |
|
133 | + public function onBinary(string $binary): void { |
|
134 | 134 | unset($binary); |
135 | 135 | throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle binary data."); |
136 | 136 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * |
141 | 141 | * The RFC says the connection must be dropped if any unsupported activity occurs. |
142 | 142 | */ |
143 | - final public function onOutOfBand (): void { |
|
143 | + final public function onOutOfBand(): void { |
|
144 | 144 | $this->close(Frame::CLOSE_PROTOCOL_ERROR, "Received out-of-band data."); |
145 | 145 | } |
146 | 146 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @throws Exception |
151 | 151 | */ |
152 | - public function onReadable (): void { |
|
152 | + public function onReadable(): void { |
|
153 | 153 | if (!strlen($this->recv(1, MSG_PEEK))) { // peer has shut down writing, or closed. |
154 | 154 | $this->close(); |
155 | 155 | return; |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | /** |
186 | 186 | * Called when the initial connection handshake succeeds and frame I/O can occur. |
187 | 187 | */ |
188 | - protected function onStateOk (): void { |
|
188 | + protected function onStateOk(): void { |
|
189 | 189 | // stub |
190 | 190 | } |
191 | 191 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param string $text |
196 | 196 | */ |
197 | - public function onText (string $text): void { |
|
197 | + public function onText(string $text): void { |
|
198 | 198 | unset($text); |
199 | 199 | throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle text."); |
200 | 200 | } |
@@ -51,21 +51,21 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * @param WebSocketClient $client |
53 | 53 | */ |
54 | - public function __construct (WebSocketClient $client) { |
|
54 | + public function __construct(WebSocketClient $client) { |
|
55 | 55 | $this->client = $client; |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @return int |
60 | 60 | */ |
61 | - public function getFragmentSize (): int { |
|
61 | + public function getFragmentSize(): int { |
|
62 | 62 | return $this->fragmentSize; |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @return int |
67 | 67 | */ |
68 | - public function getMaxLength (): int { |
|
68 | + public function getMaxLength(): int { |
|
69 | 69 | return $this->maxLength; |
70 | 70 | } |
71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @param Frame $binary |
76 | 76 | * @throws WebSocketError |
77 | 77 | */ |
78 | - protected function onBinary (Frame $binary): void { |
|
78 | + protected function onBinary(Frame $binary): void { |
|
79 | 79 | $this->buffer .= $binary->getPayload(); |
80 | 80 | if ($binary->isFinal()) { |
81 | 81 | $message = $this->buffer; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @param Frame $close |
97 | 97 | */ |
98 | - protected function onClose (Frame $close): void { |
|
98 | + protected function onClose(Frame $close): void { |
|
99 | 99 | $this->client->close($close->getCloseCode()); |
100 | 100 | } |
101 | 101 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param Frame $fragment |
106 | 106 | * @throws WebSocketError |
107 | 107 | */ |
108 | - protected function onContinue (Frame $fragment): void { |
|
108 | + protected function onContinue(Frame $fragment): void { |
|
109 | 109 | if (!$this->continue) { |
110 | 110 | throw new WebSocketError( |
111 | 111 | Frame::CLOSE_PROTOCOL_ERROR, |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @param Frame $control |
139 | 139 | */ |
140 | - protected function onControl (Frame $control): void { |
|
140 | + protected function onControl(Frame $control): void { |
|
141 | 141 | if ($control->isClose()) { |
142 | 142 | $this->onClose($control); |
143 | 143 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @param Frame $data |
156 | 156 | */ |
157 | - protected function onData (Frame $data): void { |
|
157 | + protected function onData(Frame $data): void { |
|
158 | 158 | $this->onData_SetContinue($data); |
159 | 159 | if ($data->isText()) { |
160 | 160 | $this->onText($data); |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | * @param Frame $data |
169 | 169 | * @throws WebSocketError |
170 | 170 | */ |
171 | - protected function onData_SetContinue (Frame $data): void { |
|
171 | + protected function onData_SetContinue(Frame $data): void { |
|
172 | 172 | if ($this->continue) { |
173 | 173 | throw new WebSocketError( |
174 | 174 | Frame::CLOSE_PROTOCOL_ERROR, |
175 | - "Received interleaved {$data->getName()} against existing " . Frame::NAMES[$this->continue], |
|
175 | + "Received interleaved {$data->getName()} against existing ".Frame::NAMES[$this->continue], |
|
176 | 176 | $data |
177 | 177 | ); |
178 | 178 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @param Frame $frame |
190 | 190 | */ |
191 | - public function onFrame (Frame $frame): void { |
|
191 | + public function onFrame(Frame $frame): void { |
|
192 | 192 | $this->onFrame_CheckRsv($frame); |
193 | 193 | $this->onFrame_CheckLength($frame); |
194 | 194 | if ($frame->isControl()) { |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @param Frame $frame |
207 | 207 | * @throws WebSocketError |
208 | 208 | */ |
209 | - protected function onFrame_CheckLength (Frame $frame): void { |
|
209 | + protected function onFrame_CheckLength(Frame $frame): void { |
|
210 | 210 | if ($frame->isData()) { |
211 | 211 | $length = strlen($this->buffer); |
212 | 212 | if ($length + $frame->getLength() > $this->maxLength) { |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param Frame $frame |
226 | 226 | * @throws WebSocketError |
227 | 227 | */ |
228 | - protected function onFrame_CheckRsv (Frame $frame): void { |
|
228 | + protected function onFrame_CheckRsv(Frame $frame): void { |
|
229 | 229 | if ($badRsv = $frame->getRsv() & ~$this->client->getHandshake()->getRsv()) { |
230 | 230 | $badRsv = str_pad(base_convert($badRsv >> 4, 10, 2), 3, '0', STR_PAD_LEFT); |
231 | 231 | throw new WebSocketError( |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @param Frame $ping |
245 | 245 | */ |
246 | - protected function onPing (Frame $ping): void { |
|
246 | + protected function onPing(Frame $ping): void { |
|
247 | 247 | $this->writePong($ping->getPayload()); |
248 | 248 | } |
249 | 249 | |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @param Frame $pong |
256 | 256 | */ |
257 | - protected function onPong (Frame $pong): void { |
|
257 | + protected function onPong(Frame $pong): void { |
|
258 | 258 | // stub |
259 | 259 | } |
260 | 260 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param Frame $text |
265 | 265 | * @throws WebSocketError |
266 | 266 | */ |
267 | - protected function onText (Frame $text): void { |
|
267 | + protected function onText(Frame $text): void { |
|
268 | 268 | $this->buffer .= $text->getPayload(); |
269 | 269 | if ($text->isFinal()) { |
270 | 270 | if (!mb_detect_encoding($this->buffer, 'UTF-8', true)) { |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @param int $bytes |
281 | 281 | * @return $this |
282 | 282 | */ |
283 | - public function setFragmentSize (int $bytes) { |
|
283 | + public function setFragmentSize(int $bytes) { |
|
284 | 284 | $this->fragmentSize = $bytes; |
285 | 285 | return $this; |
286 | 286 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @param int $bytes |
290 | 290 | * @return $this |
291 | 291 | */ |
292 | - public function setMaxLength (int $bytes) { |
|
292 | + public function setMaxLength(int $bytes) { |
|
293 | 293 | $this->maxLength = $bytes; |
294 | 294 | return $this; |
295 | 295 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @param int $opCode |
301 | 301 | * @param string $payload |
302 | 302 | */ |
303 | - public function write (int $opCode, string $payload): void { |
|
303 | + public function write(int $opCode, string $payload): void { |
|
304 | 304 | $offset = 0; |
305 | 305 | $total = strlen($payload); |
306 | 306 | do { |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | /** |
317 | 317 | * @param string $payload |
318 | 318 | */ |
319 | - public function writeBinary (string $payload): void { |
|
319 | + public function writeBinary(string $payload): void { |
|
320 | 320 | $this->write(Frame::OP_BINARY, $payload); |
321 | 321 | } |
322 | 322 | |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | * @param int $code |
325 | 325 | * @param string $reason |
326 | 326 | */ |
327 | - public function writeClose (int $code = Frame::CLOSE_NORMAL, string $reason = ''): void { |
|
328 | - $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code) . $reason); |
|
327 | + public function writeClose(int $code = Frame::CLOSE_NORMAL, string $reason = ''): void { |
|
328 | + $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code).$reason); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @param int $opCode |
336 | 336 | * @param string $payload |
337 | 337 | */ |
338 | - protected function writeFrame (bool $final, int $opCode, string $payload): void { |
|
338 | + protected function writeFrame(bool $final, int $opCode, string $payload): void { |
|
339 | 339 | if ($opCode & 0x08 and !$final) { |
340 | 340 | throw new LogicException("Would have sent a fragmented control frame ({$opCode}) {$payload}"); |
341 | 341 | } |
@@ -352,27 +352,27 @@ discard block |
||
352 | 352 | else { |
353 | 353 | $head .= chr($length); |
354 | 354 | } |
355 | - $this->client->write($head . $payload); |
|
355 | + $this->client->write($head.$payload); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
359 | 359 | * @param string $payload |
360 | 360 | */ |
361 | - public function writePing (string $payload = ''): void { |
|
361 | + public function writePing(string $payload = ''): void { |
|
362 | 362 | $this->writeFrame(true, Frame::OP_PING, $payload); |
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
366 | 366 | * @param string $payload |
367 | 367 | */ |
368 | - public function writePong (string $payload = ''): void { |
|
368 | + public function writePong(string $payload = ''): void { |
|
369 | 369 | $this->writeFrame(true, Frame::OP_PONG, $payload); |
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
373 | 373 | * @param string $payload |
374 | 374 | */ |
375 | - public function writeText (string $payload): void { |
|
375 | + public function writeText(string $payload): void { |
|
376 | 376 | $this->write(Frame::OP_TEXT, $payload); |
377 | 377 | } |
378 | 378 | } |
379 | 379 | \ No newline at end of file |