@@ -101,19 +101,16 @@ |
||
101 | 101 | $value = trim($value); |
102 | 102 | if (isset($this->headers[$key])) { |
103 | 103 | $this->headers[$key] .= ', ' . $value; |
104 | - } |
|
105 | - else { |
|
104 | + } else { |
|
106 | 105 | $this->headers[$key] = $value; |
107 | 106 | } |
108 | 107 | } |
109 | 108 | $this->buffer = ''; // wipe the buffer |
110 | 109 | $this->validate(); |
111 | - } |
|
112 | - catch (WebSocketError $e) { // catch and respond with HTTP error and rethrow |
|
110 | + } catch (WebSocketError $e) { // catch and respond with HTTP error and rethrow |
|
113 | 111 | $this->client->write("HTTP/1.1 {$e->getCode()} WebSocket Handshake Failure\r\n\r\n"); |
114 | 112 | throw $e; |
115 | - } |
|
116 | - catch (Throwable $e) { // catch everything else and respond with HTTP 500 and rethrow |
|
113 | + } catch (Throwable $e) { // catch everything else and respond with HTTP 500 and rethrow |
|
117 | 114 | $this->client->write("HTTP/1.1 500 WebSocket Internal Error\r\n\r\n"); |
118 | 115 | throw $e; |
119 | 116 | } |
@@ -82,8 +82,7 @@ discard block |
||
82 | 82 | if ($code >= 1000 and $this->isOk()) { |
83 | 83 | $this->frameHandler->writeClose($code, $reason); |
84 | 84 | } |
85 | - } |
|
86 | - finally { |
|
85 | + } finally { |
|
87 | 86 | $this->server->remove($this); |
88 | 87 | parent::close(); |
89 | 88 | $this->state = self::STATE_CLOSED; |
@@ -200,16 +199,13 @@ discard block |
||
200 | 199 | $this->state = self::STATE_OK; |
201 | 200 | $this->onStateOk(); |
202 | 201 | } |
203 | - } |
|
204 | - elseif ($this->isOk()) { |
|
202 | + } elseif ($this->isOk()) { |
|
205 | 203 | $this->frameHandler->onReadable(); |
206 | 204 | } |
207 | - } |
|
208 | - catch (WebSocketError $e) { |
|
205 | + } catch (WebSocketError $e) { |
|
209 | 206 | $this->close($e->getCode(), $e->getMessage()); |
210 | 207 | throw $e; |
211 | - } |
|
212 | - catch (Throwable $e) { |
|
208 | + } catch (Throwable $e) { |
|
213 | 209 | $this->close(Frame::CLOSE_INTERNAL_ERROR); |
214 | 210 | throw $e; |
215 | 211 | } |
@@ -141,19 +141,15 @@ |
||
141 | 141 | if ($badRsv = $rsv & ~$this->rsv) { |
142 | 142 | $badRsv = str_pad(base_convert($badRsv >> 4, 10, 2), 3, '0', STR_PAD_LEFT); |
143 | 143 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unknown RSV bits: 0b{$badRsv}"); |
144 | - } |
|
145 | - elseif ($opCode >= Frame::OP_CLOSE) { |
|
144 | + } elseif ($opCode >= Frame::OP_CLOSE) { |
|
146 | 145 | if ($opCode > Frame::OP_PONG) { |
147 | 146 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unsupported control frame ({$opCode})"); |
148 | - } |
|
149 | - elseif (!$final) { |
|
147 | + } elseif (!$final) { |
|
150 | 148 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received fragmented control frame ({$opCode})"); |
151 | 149 | } |
152 | - } |
|
153 | - elseif ($opCode > Frame::OP_BINARY) { |
|
150 | + } elseif ($opCode > Frame::OP_BINARY) { |
|
154 | 151 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unsupported data frame ({$opCode})"); |
155 | - } |
|
156 | - elseif ($length > $this->maxLength) { |
|
152 | + } elseif ($length > $this->maxLength) { |
|
157 | 153 | throw new WebSocketError(Frame::CLOSE_TOO_LARGE, "Payload would exceed {$this->maxLength} bytes"); |
158 | 154 | } |
159 | 155 |
@@ -105,8 +105,7 @@ discard block |
||
105 | 105 | protected function onBinary (Frame $frame): void { |
106 | 106 | if ($this->stream) { |
107 | 107 | $this->client->onBinary($frame->getPayload()); |
108 | - } |
|
109 | - else { |
|
108 | + } else { |
|
110 | 109 | $this->onData_CheckLength($frame); |
111 | 110 | $this->buffer .= $frame->getPayload(); |
112 | 111 | if ($frame->isFinal()) { |
@@ -149,12 +148,10 @@ discard block |
||
149 | 148 | try { |
150 | 149 | if ($this->continue === Frame::OP_TEXT) { |
151 | 150 | $this->onText($frame); |
152 | - } |
|
153 | - else { |
|
151 | + } else { |
|
154 | 152 | $this->onBinary($frame); |
155 | 153 | } |
156 | - } |
|
157 | - finally { |
|
154 | + } finally { |
|
158 | 155 | if ($frame->isFinal()) { |
159 | 156 | $this->continue = null; |
160 | 157 | } |
@@ -173,14 +170,11 @@ discard block |
||
173 | 170 | protected function onControl (Frame $frame): void { |
174 | 171 | if ($frame->isClose()) { |
175 | 172 | $this->onClose($frame); |
176 | - } |
|
177 | - elseif ($frame->isPing()) { |
|
173 | + } elseif ($frame->isPing()) { |
|
178 | 174 | $this->onPing($frame); |
179 | - } |
|
180 | - elseif ($frame->isPong()) { |
|
175 | + } elseif ($frame->isPong()) { |
|
181 | 176 | $this->onPong($frame); |
182 | - } |
|
183 | - else { |
|
177 | + } else { |
|
184 | 178 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Unsupported control frame.", $frame); |
185 | 179 | } |
186 | 180 | } |
@@ -248,8 +242,7 @@ discard block |
||
248 | 242 | public function onFrame (Frame $frame): void { |
249 | 243 | if ($frame->isControl()) { |
250 | 244 | $this->onControl($frame); |
251 | - } |
|
252 | - else { |
|
245 | + } else { |
|
253 | 246 | $this->onData($frame); |
254 | 247 | } |
255 | 248 | } |
@@ -378,12 +371,10 @@ discard block |
||
378 | 371 | if ($length > 65535) { |
379 | 372 | $head .= chr(127); |
380 | 373 | $head .= pack('J', $length); |
381 | - } |
|
382 | - elseif ($length >= 126) { |
|
374 | + } elseif ($length >= 126) { |
|
383 | 375 | $head .= chr(126); |
384 | 376 | $head .= pack('n', $length); |
385 | - } |
|
386 | - else { |
|
377 | + } else { |
|
387 | 378 | $head .= chr($length); |
388 | 379 | } |
389 | 380 | $this->client->write($head . $payload); |