@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return string |
| 20 | 20 | */ |
| 21 | - public function __toString () { |
|
| 21 | + public function __toString() { |
|
| 22 | 22 | try { |
| 23 | 23 | return implode(':', $this->getPeerName()); |
| 24 | 24 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @return $this |
| 42 | 42 | * @throws SocketError |
| 43 | 43 | */ |
| 44 | - public function connect (string $address, int $port = 0) { |
|
| 44 | + public function connect(string $address, int $port = 0) { |
|
| 45 | 45 | if (!@socket_connect($this->resource, $address, $port)) { |
| 46 | 46 | // ignore expected errors for non-blocking connections |
| 47 | 47 | $errno = SocketError::getLast($this->resource); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return array `[ 0 => address, 1 => port ]` |
| 62 | 62 | * @throws SocketError |
| 63 | 63 | */ |
| 64 | - public function getPeerName (): array { |
|
| 64 | + public function getPeerName(): array { |
|
| 65 | 65 | if ($this->getDomain() === AF_UNIX) { |
| 66 | 66 | return [$this->getOption(17), 0]; // SO_PEERCRED is not exposed by PHP |
| 67 | 67 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @return int Total bytes sent. |
| 82 | 82 | * @throws SocketError |
| 83 | 83 | */ |
| 84 | - public function send (string $data, int $flags = 0): int { |
|
| 84 | + public function send(string $data, int $flags = 0): int { |
|
| 85 | 85 | $count = @socket_send($this->resource, $data, strlen($data), $flags); |
| 86 | 86 | if ($count === false) { |
| 87 | 87 | throw new SocketError($this->resource); // reliable errno |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @return $this |
| 97 | 97 | * @throws SocketError `int` total bytes sent is set as the extra data. |
| 98 | 98 | */ |
| 99 | - public function write (string $data) { |
|
| 99 | + public function write(string $data) { |
|
| 100 | 100 | $length = strlen($data); |
| 101 | 101 | $total = 0; |
| 102 | 102 | while ($total < $length) { |
@@ -21,8 +21,7 @@ discard block |
||
| 21 | 21 | public function __toString () { |
| 22 | 22 | try { |
| 23 | 23 | return implode(':', $this->getPeerName()); |
| 24 | - } |
|
| 25 | - catch (Throwable $e) { |
|
| 24 | + } catch (Throwable $e) { |
|
| 26 | 25 | return "?{$this->resource}"; |
| 27 | 26 | } |
| 28 | 27 | } |
@@ -102,8 +101,7 @@ discard block |
||
| 102 | 101 | while ($total < $length) { |
| 103 | 102 | try { |
| 104 | 103 | $total += $this->awaitWritable()->send(substr($data, $total)); |
| 105 | - } |
|
| 106 | - catch (SocketError $e) { |
|
| 104 | + } catch (SocketError $e) { |
|
| 107 | 105 | $e->setExtra($total); |
| 108 | 106 | throw $e; |
| 109 | 107 | } |
@@ -27,20 +27,20 @@ |
||
| 27 | 27 | * |
| 28 | 28 | * @return int |
| 29 | 29 | */ |
| 30 | - public function getId (): int; |
|
| 30 | + public function getId(): int; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Returns the underlying socket resource. |
| 34 | 34 | * |
| 35 | 35 | * @return resource |
| 36 | 36 | */ |
| 37 | - public function getResource (); |
|
| 37 | + public function getResource(); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Whether the underlying resource is usable. |
| 41 | 41 | * |
| 42 | 42 | * @return bool |
| 43 | 43 | */ |
| 44 | - public function isOpen (): bool; |
|
| 44 | + public function isOpen(): bool; |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param resource $resource PHP socket resource, or `null` for the global error. |
| 30 | 30 | * @return int If the resource is closed or not a socket, `SOCKET_EBADF` is returned. |
| 31 | 31 | */ |
| 32 | - public static function getLast ($resource = null) { |
|
| 32 | + public static function getLast($resource = null) { |
|
| 33 | 33 | if (isset($resource)) { |
| 34 | 34 | if (@get_resource_type($resource) !== 'Socket') { |
| 35 | 35 | return SOCKET_EBADF; // Bad file descriptor |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param int $fallback Code to assume if one can't be found via the subject. |
| 63 | 63 | * @param SocketError|null $previous Slippage of a prior error. |
| 64 | 64 | */ |
| 65 | - public function __construct ($subject = null, $fallback = 0, SocketError $previous = null) { |
|
| 65 | + public function __construct($subject = null, $fallback = 0, SocketError $previous = null) { |
|
| 66 | 66 | if ($errno = is_int($subject) ? $subject : static::getLast($subject)) { |
| 67 | 67 | $message = socket_strerror($errno); |
| 68 | 68 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | /** |
| 78 | 78 | * @return mixed |
| 79 | 79 | */ |
| 80 | - public function getExtra () { |
|
| 80 | + public function getExtra() { |
|
| 81 | 81 | return $this->extra; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param mixed $extra |
| 86 | 86 | * @return $this |
| 87 | 87 | */ |
| 88 | - public function setExtra ($extra) { |
|
| 88 | + public function setExtra($extra) { |
|
| 89 | 89 | $this->extra = $extra; |
| 90 | 90 | return $this; |
| 91 | 91 | } |
@@ -65,8 +65,7 @@ |
||
| 65 | 65 | public function __construct ($subject = null, $fallback = 0, SocketError $previous = null) { |
| 66 | 66 | if ($errno = is_int($subject) ? $subject : static::getLast($subject)) { |
| 67 | 67 | $message = socket_strerror($errno); |
| 68 | - } |
|
| 69 | - else { |
|
| 68 | + } else { |
|
| 70 | 69 | $errno = $fallback; |
| 71 | 70 | $last = error_get_last(); |
| 72 | 71 | $message = "{$last['message']} in {$last['file']}:{$last['line']}"; |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | $length -= $chunkSize = strlen($chunk); |
| 54 | 54 | } while ($chunkSize and $length); |
| 55 | 55 | return $data; |
| 56 | - } |
|
| 57 | - catch (SocketError $e) { |
|
| 56 | + } catch (SocketError $e) { |
|
| 58 | 57 | $e->setExtra($data); |
| 59 | 58 | throw $e; |
| 60 | 59 | } |
@@ -91,8 +90,7 @@ discard block |
||
| 91 | 90 | $length = $this->getOption(SO_RCVBUF); |
| 92 | 91 | try { |
| 93 | 92 | return $this->recv($length, $msgFlags); |
| 94 | - } |
|
| 95 | - catch (SocketError $e) { |
|
| 93 | + } catch (SocketError $e) { |
|
| 96 | 94 | if ($e->getCode() === SOCKET_EAGAIN) { // would block |
| 97 | 95 | return ''; |
| 98 | 96 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | * @link https://php.net/socket_create_pair |
| 24 | 24 | * |
| 25 | 25 | * @param array $extra Variadic constructor arguments. |
| 26 | - * @return static[] Two instances at indices `0` and `1`. |
|
| 26 | + * @return StreamClient[] Two instances at indices `0` and `1`. |
|
| 27 | 27 | * @throws SocketError |
| 28 | 28 | */ |
| 29 | 29 | public static function newUnixPair (...$extra) { |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return int |
| 14 | 14 | */ |
| 15 | - final public static function getType (): int { |
|
| 15 | + final public static function getType(): int { |
|
| 16 | 16 | return SOCK_STREAM; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * @return static[] Two instances at indices `0` and `1`. |
| 27 | 27 | * @throws SocketError |
| 28 | 28 | */ |
| 29 | - public static function newUnixPair (...$extra) { |
|
| 29 | + public static function newUnixPair(...$extra) { |
|
| 30 | 30 | if (!@socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $fd)) { |
| 31 | 31 | throw new SocketError; // reliable errno |
| 32 | 32 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @return string |
| 46 | 46 | * @throws SocketError The partially read data is attached. |
| 47 | 47 | */ |
| 48 | - public function read (int $length): string { |
|
| 48 | + public function read(int $length): string { |
|
| 49 | 49 | try { |
| 50 | 50 | $data = ''; |
| 51 | 51 | do { |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | * @return string |
| 73 | 73 | * @throws SocketError |
| 74 | 74 | */ |
| 75 | - public function recv (int $maxLength, int $msgFlags = 0): string { |
|
| 75 | + public function recv(int $maxLength, int $msgFlags = 0): string { |
|
| 76 | 76 | if (false === @socket_recv($this->resource, $data, $maxLength, $msgFlags)) { |
| 77 | 77 | throw new SocketError($this->resource, SOCKET_EINVAL); |
| 78 | 78 | } |
| 79 | - return (string)$data; // cast needed, will be null if 0 bytes are read. |
|
| 79 | + return (string) $data; // cast needed, will be null if 0 bytes are read. |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return string |
| 87 | 87 | * @throws SocketError |
| 88 | 88 | */ |
| 89 | - public function recvAll (int $msgFlags = 0): string { |
|
| 89 | + public function recvAll(int $msgFlags = 0): string { |
|
| 90 | 90 | $msgFlags = ($msgFlags & ~MSG_WAITALL) | MSG_DONTWAIT; |
| 91 | 91 | $length = $this->getOption(SO_RCVBUF); |
| 92 | 92 | try { |
@@ -52,11 +52,9 @@ |
||
| 52 | 52 | public function __construct ($resource) { |
| 53 | 53 | if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') { |
| 54 | 54 | throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF); |
| 55 | - } |
|
| 56 | - elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
|
| 55 | + } elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
|
| 57 | 56 | throw new InvalidArgumentException('Invalid socket type for ' . static::class, SOCKET_ESOCKTNOSUPPORT); |
| 58 | - } |
|
| 59 | - elseif ($errno = SocketError::getLast($resource)) { |
|
| 57 | + } elseif ($errno = SocketError::getLast($resource)) { |
|
| 60 | 58 | // "File descriptor in bad state" |
| 61 | 59 | throw new SocketError(SOCKET_EBADFD, 0, new SocketError($errno)); |
| 62 | 60 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @link https://php.net/socket_get_option |
| 155 | 155 | * |
| 156 | 156 | * @param int $option `SO_*` option constant. |
| 157 | - * @return mixed The option's value. This is never `false`. |
|
| 157 | + * @return integer The option's value. This is never `false`. |
|
| 158 | 158 | * @throws SocketError |
| 159 | 159 | */ |
| 160 | 160 | public function getOption (int $option) { |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @see await() |
| 223 | 223 | * |
| 224 | 224 | * @param int $channel `SocketInterface` channel constant. |
| 225 | - * @param float|null $timeout Maximum seconds to block. `NULL` blocks forever. Defaults to a poll. |
|
| 225 | + * @param integer $timeout Maximum seconds to block. `NULL` blocks forever. Defaults to a poll. |
|
| 226 | 226 | * @return bool |
| 227 | 227 | * @throws SocketError |
| 228 | 228 | */ |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @return int |
| 16 | 16 | */ |
| 17 | - abstract public static function getType (): int; |
|
| 17 | + abstract public static function getType(): int; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * The underlying PHP resource. |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @return static |
| 34 | 34 | * @throws SocketError |
| 35 | 35 | */ |
| 36 | - public static function create (int $domain = AF_INET, ...$extra) { |
|
| 36 | + public static function create(int $domain = AF_INET, ...$extra) { |
|
| 37 | 37 | if (!$resource = @socket_create($domain, static::getType(), 0)) { // auto-protocol |
| 38 | 38 | throw new SocketError; // reliable errno |
| 39 | 39 | } |
@@ -49,12 +49,12 @@ discard block |
||
| 49 | 49 | * @throws InvalidArgumentException Not a socket resource, or the socket is of the wrong type. |
| 50 | 50 | * @throws SocketError Slippage of an existing error on the resource. |
| 51 | 51 | */ |
| 52 | - public function __construct ($resource) { |
|
| 52 | + public function __construct($resource) { |
|
| 53 | 53 | if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') { |
| 54 | 54 | throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF); |
| 55 | 55 | } |
| 56 | 56 | elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
| 57 | - throw new InvalidArgumentException('Invalid socket type for ' . static::class, SOCKET_ESOCKTNOSUPPORT); |
|
| 57 | + throw new InvalidArgumentException('Invalid socket type for '.static::class, SOCKET_ESOCKTNOSUPPORT); |
|
| 58 | 58 | } |
| 59 | 59 | elseif ($errno = SocketError::getLast($resource)) { |
| 60 | 60 | // "File descriptor in bad state" |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @see close() |
| 70 | 70 | */ |
| 71 | - public function __destruct () { |
|
| 71 | + public function __destruct() { |
|
| 72 | 72 | if ($this->isOpen()) { |
| 73 | 73 | $this->close(); |
| 74 | 74 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @return $this |
| 86 | 86 | * @throws SocketError |
| 87 | 87 | */ |
| 88 | - public function await (int $channel) { |
|
| 88 | + public function await(int $channel) { |
|
| 89 | 89 | $rwe = [$channel => [$this->resource]]; |
| 90 | 90 | if (!@socket_select($rwe[0], $rwe[1], $rwe[2], null)) { |
| 91 | 91 | throw new SocketError($this->resource); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @return $this |
| 100 | 100 | */ |
| 101 | - final public function awaitOutOfBand () { |
|
| 101 | + final public function awaitOutOfBand() { |
|
| 102 | 102 | return $this->await(self::CH_EXCEPT); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return $this |
| 109 | 109 | */ |
| 110 | - final public function awaitReadable () { |
|
| 110 | + final public function awaitReadable() { |
|
| 111 | 111 | return $this->await(self::CH_READ); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return $this |
| 118 | 118 | */ |
| 119 | - final public function awaitWritable () { |
|
| 119 | + final public function awaitWritable() { |
|
| 120 | 120 | return $this->await(self::CH_WRITE); |
| 121 | 121 | } |
| 122 | 122 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @return $this |
| 129 | 129 | */ |
| 130 | - public function close () { |
|
| 130 | + public function close() { |
|
| 131 | 131 | socket_close($this->resource); // never errors |
| 132 | 132 | return $this; |
| 133 | 133 | } |
@@ -137,15 +137,15 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return int |
| 139 | 139 | */ |
| 140 | - final public function getDomain (): int { |
|
| 140 | + final public function getDomain(): int { |
|
| 141 | 141 | return $this->getOption(39); // SO_DOMAIN is not exposed by PHP |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | 145 | * @inheritDoc |
| 146 | 146 | */ |
| 147 | - final public function getId (): int { |
|
| 148 | - return (int)$this->resource; |
|
| 147 | + final public function getId(): int { |
|
| 148 | + return (int) $this->resource; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @return mixed The option's value. This is never `false`. |
| 158 | 158 | * @throws SocketError |
| 159 | 159 | */ |
| 160 | - public function getOption (int $option) { |
|
| 160 | + public function getOption(int $option) { |
|
| 161 | 161 | $value = @socket_get_option($this->resource, SOL_SOCKET, $option); |
| 162 | 162 | if ($value === false) { |
| 163 | 163 | throw new SocketError($this->resource, SOCKET_EINVAL); |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | /** |
| 169 | 169 | * @inheritDoc |
| 170 | 170 | */ |
| 171 | - final public function getResource () { |
|
| 171 | + final public function getResource() { |
|
| 172 | 172 | return $this->resource; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @return array `[ 0 => address, 1 => port ]` |
| 181 | 181 | * @throws SocketError |
| 182 | 182 | */ |
| 183 | - public function getSockName (): array { |
|
| 183 | + public function getSockName(): array { |
|
| 184 | 184 | if (!@socket_getsockname($this->resource, $addr, $port)) { |
| 185 | 185 | throw new SocketError($this->resource, SOCKET_EOPNOTSUPP); |
| 186 | 186 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | /** |
| 191 | 191 | * @inheritDoc |
| 192 | 192 | */ |
| 193 | - public function isOpen (): bool { |
|
| 193 | + public function isOpen(): bool { |
|
| 194 | 194 | return is_resource($this->resource); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @return bool |
| 203 | 203 | */ |
| 204 | - final public function isOutOfBand (): bool { |
|
| 204 | + final public function isOutOfBand(): bool { |
|
| 205 | 205 | return $this->isReady(self::CH_EXCEPT); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * |
| 213 | 213 | * @return bool |
| 214 | 214 | */ |
| 215 | - final public function isReadable (): bool { |
|
| 215 | + final public function isReadable(): bool { |
|
| 216 | 216 | return $this->isReady(self::CH_READ); |
| 217 | 217 | } |
| 218 | 218 | |
@@ -226,15 +226,15 @@ discard block |
||
| 226 | 226 | * @return bool |
| 227 | 227 | * @throws SocketError |
| 228 | 228 | */ |
| 229 | - public function isReady (int $channel, ?float $timeout = 0): bool { |
|
| 229 | + public function isReady(int $channel, ?float $timeout = 0): bool { |
|
| 230 | 230 | $rwe = [$channel => [$this->resource]]; |
| 231 | 231 | // core casts non-null timeout to int. |
| 232 | 232 | // usec is ignored if timeout is null. |
| 233 | - $usec = (int)(fmod($timeout, 1) * 1000000); |
|
| 233 | + $usec = (int) (fmod($timeout, 1) * 1000000); |
|
| 234 | 234 | if (false === $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $usec)) { |
| 235 | 235 | throw new SocketError($this->resource); |
| 236 | 236 | } |
| 237 | - return (bool)$count; |
|
| 237 | + return (bool) $count; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @return bool |
| 246 | 246 | */ |
| 247 | - final public function isWritable (): bool { |
|
| 247 | + final public function isWritable(): bool { |
|
| 248 | 248 | return $this->isReady(self::CH_WRITE); |
| 249 | 249 | } |
| 250 | 250 | |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | * @return $this |
| 267 | 267 | * @throws SocketError |
| 268 | 268 | */ |
| 269 | - public function setBlocking (bool $blocking) { |
|
| 269 | + public function setBlocking(bool $blocking) { |
|
| 270 | 270 | if ($blocking ? @socket_set_block($this->resource) : @socket_set_nonblock($this->resource)) { |
| 271 | 271 | return $this; |
| 272 | 272 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return $this |
| 284 | 284 | * @throws SocketError |
| 285 | 285 | */ |
| 286 | - public function setOption (int $option, $value) { |
|
| 286 | + public function setOption(int $option, $value) { |
|
| 287 | 287 | if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) { |
| 288 | 288 | throw new SocketError($this->resource, SOCKET_EINVAL); |
| 289 | 289 | } |
@@ -296,10 +296,10 @@ discard block |
||
| 296 | 296 | * @param float $timeout Zero means "no timeout" (block forever). |
| 297 | 297 | * @return $this |
| 298 | 298 | */ |
| 299 | - public function setTimeout (float $timeout) { |
|
| 299 | + public function setTimeout(float $timeout) { |
|
| 300 | 300 | $tv = [ |
| 301 | - 'sec' => (int)$timeout, |
|
| 302 | - 'usec' => (int)(fmod($timeout, 1) * 1000000) |
|
| 301 | + 'sec' => (int) $timeout, |
|
| 302 | + 'usec' => (int) (fmod($timeout, 1) * 1000000) |
|
| 303 | 303 | ]; |
| 304 | 304 | $this->setOption(SO_RCVTIMEO, $tv); |
| 305 | 305 | $this->setOption(SO_SNDTIMEO, $tv); |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @return $this |
| 330 | 330 | * @throws SocketError |
| 331 | 331 | */ |
| 332 | - public function shutdown (int $channel) { |
|
| 332 | + public function shutdown(int $channel) { |
|
| 333 | 333 | if (!@socket_shutdown($this->resource, $channel)) { |
| 334 | 334 | throw new SocketError($this->resource); // reliable errno |
| 335 | 335 | } |
@@ -53,21 +53,21 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | protected $text = ''; |
| 55 | 55 | |
| 56 | - public function __construct (WebSocketClient $client) { |
|
| 56 | + public function __construct(WebSocketClient $client) { |
|
| 57 | 57 | $this->client = $client; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @return int |
| 62 | 62 | */ |
| 63 | - public function getFragmentSize (): int { |
|
| 63 | + public function getFragmentSize(): int { |
|
| 64 | 64 | return $this->fragmentSize; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @return int |
| 69 | 69 | */ |
| 70 | - public function getMaxLength (): int { |
|
| 70 | + public function getMaxLength(): int { |
|
| 71 | 71 | return $this->maxLength; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param Frame $binary |
| 80 | 80 | * @throws WebSocketError |
| 81 | 81 | */ |
| 82 | - protected function onBinary (Frame $binary): void { |
|
| 82 | + protected function onBinary(Frame $binary): void { |
|
| 83 | 83 | $this->binary .= $binary->getPayload(); |
| 84 | 84 | if ($binary->isFinal()) { |
| 85 | 85 | $message = $this->binary; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @param Frame $close |
| 101 | 101 | */ |
| 102 | - protected function onClose (Frame $close): void { |
|
| 102 | + protected function onClose(Frame $close): void { |
|
| 103 | 103 | $this->client->close($close->getCloseCode()); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @param Frame $frame |
| 110 | 110 | * @throws WebSocketError |
| 111 | 111 | */ |
| 112 | - protected function onContinue (Frame $frame): void { |
|
| 112 | + protected function onContinue(Frame $frame): void { |
|
| 113 | 113 | switch ($this->continue) { |
| 114 | 114 | case Frame::OP_TEXT: |
| 115 | 115 | $this->onText($frame); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @param Frame $control |
| 137 | 137 | */ |
| 138 | - protected function onControl (Frame $control): void { |
|
| 138 | + protected function onControl(Frame $control): void { |
|
| 139 | 139 | if ($control->isClose()) { |
| 140 | 140 | $this->onClose($control); |
| 141 | 141 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @param Frame $data |
| 154 | 154 | */ |
| 155 | - protected function onData (Frame $data): void { |
|
| 155 | + protected function onData(Frame $data): void { |
|
| 156 | 156 | if (!$data->isFinal()) { |
| 157 | 157 | $this->onData_SetContinue($data); |
| 158 | 158 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - protected function onData_SetContinue (Frame $data): void { |
|
| 167 | + protected function onData_SetContinue(Frame $data): void { |
|
| 168 | 168 | if ($this->continue) { |
| 169 | 169 | $existing = Frame::NAMES[$this->continue]; |
| 170 | 170 | throw new WebSocketError( |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @param Frame $frame |
| 185 | 185 | */ |
| 186 | - public function onFrame (Frame $frame): void { |
|
| 186 | + public function onFrame(Frame $frame): void { |
|
| 187 | 187 | $this->onFrame_CheckRsv($frame); |
| 188 | 188 | $this->onFrame_CheckLength($frame); |
| 189 | 189 | if ($frame->isControl()) { |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | /** |
| 201 | 201 | * @param Frame $frame |
| 202 | 202 | */ |
| 203 | - protected function onFrame_CheckLength (Frame $frame): void { |
|
| 203 | + protected function onFrame_CheckLength(Frame $frame): void { |
|
| 204 | 204 | if ($frame->isData()) { |
| 205 | 205 | if ($frame->isBinary()) { |
| 206 | 206 | $length = strlen($this->binary); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @param Frame $frame |
| 225 | 225 | * @throws WebSocketError |
| 226 | 226 | */ |
| 227 | - protected function onFrame_CheckRsv (Frame $frame): void { |
|
| 227 | + protected function onFrame_CheckRsv(Frame $frame): void { |
|
| 228 | 228 | if ($badRsv = $frame->getRsv() & ~$this->client->getHandshake()->getRsv()) { |
| 229 | 229 | $badRsv = str_pad(base_convert($badRsv >> 4, 10, 2), 3, '0', STR_PAD_LEFT); |
| 230 | 230 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unknown RSV bits: 0b{$badRsv}"); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * |
| 239 | 239 | * @param Frame $ping |
| 240 | 240 | */ |
| 241 | - protected function onPing (Frame $ping): void { |
|
| 241 | + protected function onPing(Frame $ping): void { |
|
| 242 | 242 | $this->writePong($ping->getPayload()); |
| 243 | 243 | } |
| 244 | 244 | |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @param Frame $pong |
| 251 | 251 | */ |
| 252 | - protected function onPong (Frame $pong): void { |
|
| 252 | + protected function onPong(Frame $pong): void { |
|
| 253 | 253 | // stub |
| 254 | 254 | } |
| 255 | 255 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @param Frame $text |
| 262 | 262 | * @throws WebSocketError |
| 263 | 263 | */ |
| 264 | - protected function onText (Frame $text): void { |
|
| 264 | + protected function onText(Frame $text): void { |
|
| 265 | 265 | $this->text .= $text->getPayload(); |
| 266 | 266 | if ($text->isFinal()) { |
| 267 | 267 | $message = $this->text; |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @param int $bytes |
| 275 | 275 | * @return $this |
| 276 | 276 | */ |
| 277 | - public function setFragmentSize (int $bytes) { |
|
| 277 | + public function setFragmentSize(int $bytes) { |
|
| 278 | 278 | $this->fragmentSize = $bytes; |
| 279 | 279 | return $this; |
| 280 | 280 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @param int $bytes |
| 284 | 284 | * @return $this |
| 285 | 285 | */ |
| 286 | - public function setMaxLength (int $bytes) { |
|
| 286 | + public function setMaxLength(int $bytes) { |
|
| 287 | 287 | $this->maxLength = $bytes; |
| 288 | 288 | return $this; |
| 289 | 289 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * @param int $opCode |
| 295 | 295 | * @param string $payload |
| 296 | 296 | */ |
| 297 | - public function write (int $opCode, string $payload): void { |
|
| 297 | + public function write(int $opCode, string $payload): void { |
|
| 298 | 298 | $offset = 0; |
| 299 | 299 | $total = strlen($payload); |
| 300 | 300 | do { |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | /** |
| 311 | 311 | * @param string $payload |
| 312 | 312 | */ |
| 313 | - public function writeBinary (string $payload): void { |
|
| 313 | + public function writeBinary(string $payload): void { |
|
| 314 | 314 | $this->write(Frame::OP_BINARY, $payload); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -318,8 +318,8 @@ discard block |
||
| 318 | 318 | * @param int $code |
| 319 | 319 | * @param string $reason |
| 320 | 320 | */ |
| 321 | - public function writeClose (int $code = Frame::CLOSE_NORMAL, string $reason = ''): void { |
|
| 322 | - $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code) . $reason); |
|
| 321 | + public function writeClose(int $code = Frame::CLOSE_NORMAL, string $reason = ''): void { |
|
| 322 | + $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code).$reason); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @param int $opCode |
| 330 | 330 | * @param string $payload |
| 331 | 331 | */ |
| 332 | - protected function writeFrame (bool $final, int $opCode, string $payload): void { |
|
| 332 | + protected function writeFrame(bool $final, int $opCode, string $payload): void { |
|
| 333 | 333 | if ($opCode & 0x08 and !$final) { |
| 334 | 334 | throw new WebSocketError( |
| 335 | 335 | Frame::CLOSE_INTERNAL_ERROR, |
@@ -349,27 +349,27 @@ discard block |
||
| 349 | 349 | else { |
| 350 | 350 | $head .= chr($length); |
| 351 | 351 | } |
| 352 | - $this->client->write($head . $payload); |
|
| 352 | + $this->client->write($head.$payload); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
| 356 | 356 | * @param string $payload |
| 357 | 357 | */ |
| 358 | - public function writePing (string $payload = ''): void { |
|
| 358 | + public function writePing(string $payload = ''): void { |
|
| 359 | 359 | $this->writeFrame(true, Frame::OP_PING, $payload); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
| 363 | 363 | * @param string $payload |
| 364 | 364 | */ |
| 365 | - public function writePong (string $payload = ''): void { |
|
| 365 | + public function writePong(string $payload = ''): void { |
|
| 366 | 366 | $this->writeFrame(true, Frame::OP_PONG, $payload); |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
| 370 | 370 | * @param string $payload |
| 371 | 371 | */ |
| 372 | - public function writeText (string $payload): void { |
|
| 372 | + public function writeText(string $payload): void { |
|
| 373 | 373 | $this->write(Frame::OP_TEXT, $payload); |
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | \ No newline at end of file |
@@ -138,11 +138,9 @@ discard block |
||
| 138 | 138 | protected function onControl (Frame $control): void { |
| 139 | 139 | if ($control->isClose()) { |
| 140 | 140 | $this->onClose($control); |
| 141 | - } |
|
| 142 | - elseif ($control->isPing()) { |
|
| 141 | + } elseif ($control->isPing()) { |
|
| 143 | 142 | $this->onPing($control); |
| 144 | - } |
|
| 145 | - elseif ($control->isPong()) { |
|
| 143 | + } elseif ($control->isPong()) { |
|
| 146 | 144 | $this->onPong($control); |
| 147 | 145 | } |
| 148 | 146 | } |
@@ -158,8 +156,7 @@ discard block |
||
| 158 | 156 | } |
| 159 | 157 | if ($data->isText()) { |
| 160 | 158 | $this->onText($data); |
| 161 | - } |
|
| 162 | - elseif ($data->isBinary()) { |
|
| 159 | + } elseif ($data->isBinary()) { |
|
| 163 | 160 | $this->onBinary($data); |
| 164 | 161 | } |
| 165 | 162 | } |
@@ -188,11 +185,9 @@ discard block |
||
| 188 | 185 | $this->onFrame_CheckLength($frame); |
| 189 | 186 | if ($frame->isControl()) { |
| 190 | 187 | $this->onControl($frame); |
| 191 | - } |
|
| 192 | - elseif ($frame->isContinue()) { |
|
| 188 | + } elseif ($frame->isContinue()) { |
|
| 193 | 189 | $this->onContinue($frame); |
| 194 | - } |
|
| 195 | - else { |
|
| 190 | + } else { |
|
| 196 | 191 | $this->onData($frame); |
| 197 | 192 | } |
| 198 | 193 | } |
@@ -204,8 +199,7 @@ discard block |
||
| 204 | 199 | if ($frame->isData()) { |
| 205 | 200 | if ($frame->isBinary()) { |
| 206 | 201 | $length = strlen($this->binary); |
| 207 | - } |
|
| 208 | - else { |
|
| 202 | + } else { |
|
| 209 | 203 | $length = strlen($this->text); |
| 210 | 204 | } |
| 211 | 205 | if ($length + $frame->getLength() > $this->maxLength) { |
@@ -341,12 +335,10 @@ discard block |
||
| 341 | 335 | if ($length > 65535) { |
| 342 | 336 | $head .= chr(127); |
| 343 | 337 | $head .= pack('J', $length); |
| 344 | - } |
|
| 345 | - elseif ($length >= 126) { |
|
| 338 | + } elseif ($length >= 126) { |
|
| 346 | 339 | $head .= chr(126); |
| 347 | 340 | $head .= pack('n', $length); |
| 348 | - } |
|
| 349 | - else { |
|
| 341 | + } else { |
|
| 350 | 342 | $head .= chr($length); |
| 351 | 343 | } |
| 352 | 344 | $this->client->write($head . $payload); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param $resource |
| 30 | 30 | * @param Reactor $reactor |
| 31 | 31 | */ |
| 32 | - public function __construct ($resource, Reactor $reactor) { |
|
| 32 | + public function __construct($resource, Reactor $reactor) { |
|
| 33 | 33 | parent::__construct($resource); |
| 34 | 34 | $reactor->add($this); |
| 35 | 35 | $this->reactor = $reactor; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | /** |
| 39 | 39 | * @return WebSocketClient |
| 40 | 40 | */ |
| 41 | - public function accept () { |
|
| 41 | + public function accept() { |
|
| 42 | 42 | /** @var WebSocketClient $client */ |
| 43 | 43 | $client = parent::accept(); |
| 44 | 44 | $this->clients[$client->getId()] = $client; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param int $opCode |
| 53 | 53 | * @param string $payload |
| 54 | 54 | */ |
| 55 | - public function broadcast (int $opCode, string $payload) { |
|
| 55 | + public function broadcast(int $opCode, string $payload) { |
|
| 56 | 56 | foreach ($this->clients as $client) { |
| 57 | 57 | if ($client->isOk()) { |
| 58 | 58 | $client->getFrameHandler()->write($opCode, $payload); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * @param string $payload |
| 65 | 65 | */ |
| 66 | - public function broadcastBinary (string $payload) { |
|
| 66 | + public function broadcastBinary(string $payload) { |
|
| 67 | 67 | $this->broadcast(Frame::OP_BINARY, $payload); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param string $payload |
| 74 | 74 | */ |
| 75 | - public function broadcastPing (string $payload = '') { |
|
| 75 | + public function broadcastPing(string $payload = '') { |
|
| 76 | 76 | $this->broadcast(Frame::OP_PING, $payload); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @param string $text |
| 83 | 83 | */ |
| 84 | - public function broadcastText (string $text) { |
|
| 84 | + public function broadcastText(string $text) { |
|
| 85 | 85 | $this->broadcast(Frame::OP_TEXT, $text); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @param string $reason |
| 93 | 93 | * @return StreamServer |
| 94 | 94 | */ |
| 95 | - public function close (int $code = Frame::CLOSE_INTERRUPT, $reason = '') { |
|
| 95 | + public function close(int $code = Frame::CLOSE_INTERRUPT, $reason = '') { |
|
| 96 | 96 | foreach ($this->clients as $client) { |
| 97 | 97 | try { |
| 98 | 98 | $client->close($code, $reason); |
@@ -110,14 +110,14 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return int |
| 112 | 112 | */ |
| 113 | - public function count (): int { |
|
| 113 | + public function count(): int { |
|
| 114 | 114 | return count($this->clients); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * @return WebSocketClient[] |
| 119 | 119 | */ |
| 120 | - public function getClients () { |
|
| 120 | + public function getClients() { |
|
| 121 | 121 | return $this->clients; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param resource $resource |
| 126 | 126 | * @return WebSocketClient |
| 127 | 127 | */ |
| 128 | - protected function newClient ($resource) { |
|
| 128 | + protected function newClient($resource) { |
|
| 129 | 129 | return new WebSocketClient($resource, $this); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -134,13 +134,13 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @inheritDoc |
| 136 | 136 | */ |
| 137 | - final public function onOutOfBand (): void { |
|
| 137 | + final public function onOutOfBand(): void { |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * @inheritDoc |
| 142 | 142 | */ |
| 143 | - public function onReadable (): void { |
|
| 143 | + public function onReadable(): void { |
|
| 144 | 144 | $this->accept(); |
| 145 | 145 | } |
| 146 | 146 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * |
| 150 | 150 | * @param WebSocketClient $client |
| 151 | 151 | */ |
| 152 | - public function remove (WebSocketClient $client) { |
|
| 152 | + public function remove(WebSocketClient $client) { |
|
| 153 | 153 | unset($this->clients[$client->getId()]); |
| 154 | 154 | $this->reactor->remove($client); |
| 155 | 155 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param $resource |
| 52 | 52 | * @param WebSocketServer $server |
| 53 | 53 | */ |
| 54 | - public function __construct ($resource, WebSocketServer $server) { |
|
| 54 | + public function __construct($resource, WebSocketServer $server) { |
|
| 55 | 55 | parent::__construct($resource); |
| 56 | 56 | $this->server = $server; |
| 57 | 57 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param string $reason |
| 75 | 75 | * @return StreamClient|void |
| 76 | 76 | */ |
| 77 | - public function close (int $code = null, string $reason = '') { |
|
| 77 | + public function close(int $code = null, string $reason = '') { |
|
| 78 | 78 | try { |
| 79 | 79 | if ($code >= 1000 and $this->state === self::STATE_OK) { |
| 80 | 80 | $this->getFrameHandler()->writeClose($code, $reason); |
@@ -91,49 +91,49 @@ discard block |
||
| 91 | 91 | /** |
| 92 | 92 | * @return FrameHandler |
| 93 | 93 | */ |
| 94 | - public function getFrameHandler () { |
|
| 94 | + public function getFrameHandler() { |
|
| 95 | 95 | return $this->frameHandler ?? $this->frameHandler = new FrameHandler($this); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * @return FrameReader |
| 100 | 100 | */ |
| 101 | - public function getFrameReader () { |
|
| 101 | + public function getFrameReader() { |
|
| 102 | 102 | return $this->frameReader ?? $this->frameReader = new FrameReader($this); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * @return HandShake |
| 107 | 107 | */ |
| 108 | - public function getHandshake () { |
|
| 108 | + public function getHandshake() { |
|
| 109 | 109 | return $this->handshake ?? $this->handshake = new HandShake($this); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * @return MessageHandler |
| 114 | 114 | */ |
| 115 | - public function getMessageHandler () { |
|
| 115 | + public function getMessageHandler() { |
|
| 116 | 116 | return $this->messageHandler ?? $this->messageHandler = new MessageHandler($this); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * @return WebSocketServer |
| 121 | 121 | */ |
| 122 | - public function getServer () { |
|
| 122 | + public function getServer() { |
|
| 123 | 123 | return $this->server; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * @return int |
| 128 | 128 | */ |
| 129 | - public function getState (): int { |
|
| 129 | + public function getState(): int { |
|
| 130 | 130 | return $this->state; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * @return bool |
| 135 | 135 | */ |
| 136 | - final public function isOk (): bool { |
|
| 136 | + final public function isOk(): bool { |
|
| 137 | 137 | return $this->state === self::STATE_OK; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * The RFC says the connection must be dropped if any unsupported activity occurs. |
| 144 | 144 | */ |
| 145 | - final public function onOutOfBand (): void { |
|
| 145 | + final public function onOutOfBand(): void { |
|
| 146 | 146 | $this->close(Frame::CLOSE_PROTOCOL_ERROR, "Received out-of-band data."); |
| 147 | 147 | } |
| 148 | 148 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @throws Exception |
| 153 | 153 | */ |
| 154 | - public function onReadable (): void { |
|
| 154 | + public function onReadable(): void { |
|
| 155 | 155 | if (!strlen($this->recv(1, MSG_PEEK))) { // peer has shut down writing, or closed. |
| 156 | 156 | $this->close(); |
| 157 | 157 | return; |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | /** |
| 188 | 188 | * Stub. |
| 189 | 189 | */ |
| 190 | - protected function onStateOk (): void { |
|
| 190 | + protected function onStateOk(): void { |
|
| 191 | 191 | |
| 192 | 192 | } |
| 193 | 193 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @param FrameHandler $frameHandler |
| 196 | 196 | * @return $this |
| 197 | 197 | */ |
| 198 | - public function setFrameHandler (FrameHandler $frameHandler) { |
|
| 198 | + public function setFrameHandler(FrameHandler $frameHandler) { |
|
| 199 | 199 | $this->frameHandler = $frameHandler; |
| 200 | 200 | return $this; |
| 201 | 201 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @param FrameReader $frameReader |
| 205 | 205 | * @return $this |
| 206 | 206 | */ |
| 207 | - public function setFrameReader (FrameReader $frameReader) { |
|
| 207 | + public function setFrameReader(FrameReader $frameReader) { |
|
| 208 | 208 | $this->frameReader = $frameReader; |
| 209 | 209 | return $this; |
| 210 | 210 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @param MessageHandler $messageHandler |
| 214 | 214 | * @return $this |
| 215 | 215 | */ |
| 216 | - public function setMessageHandler (MessageHandler $messageHandler) { |
|
| 216 | + public function setMessageHandler(MessageHandler $messageHandler) { |
|
| 217 | 217 | $this->messageHandler = $messageHandler; |
| 218 | 218 | return $this; |
| 219 | 219 | } |
@@ -80,8 +80,7 @@ discard block |
||
| 80 | 80 | $this->getFrameHandler()->writeClose($code, $reason); |
| 81 | 81 | $this->shutdown(self::CH_WRITE); |
| 82 | 82 | } |
| 83 | - } |
|
| 84 | - finally { |
|
| 83 | + } finally { |
|
| 85 | 84 | $this->state = self::STATE_CLOSE; |
| 86 | 85 | $this->server->remove($this); |
| 87 | 86 | parent::close(); |
@@ -173,12 +172,10 @@ discard block |
||
| 173 | 172 | case self::STATE_CLOSE: |
| 174 | 173 | return; |
| 175 | 174 | } |
| 176 | - } |
|
| 177 | - catch (WebSocketError $e) { |
|
| 175 | + } catch (WebSocketError $e) { |
|
| 178 | 176 | $this->close($e->getCode(), $e->getMessage()); |
| 179 | 177 | throw $e; |
| 180 | - } |
|
| 181 | - catch (Exception $e) { |
|
| 178 | + } catch (Exception $e) { |
|
| 182 | 179 | $this->close(Frame::CLOSE_INTERNAL_ERROR); |
| 183 | 180 | throw $e; |
| 184 | 181 | } |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @param WebSocketClient $client |
| 14 | 14 | */ |
| 15 | - public function __construct (WebSocketClient $client) { |
|
| 15 | + public function __construct(WebSocketClient $client) { |
|
| 16 | 16 | $this->client = $client; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @param string $binary |
| 21 | 21 | */ |
| 22 | - public function onBinary (string $binary): void { |
|
| 22 | + public function onBinary(string $binary): void { |
|
| 23 | 23 | unset($binary); |
| 24 | 24 | throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle binary data."); |
| 25 | 25 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @param string $text |
| 29 | 29 | */ |
| 30 | - public function onText (string $text): void { |
|
| 30 | + public function onText(string $text): void { |
|
| 31 | 31 | $this->onText_CheckUtf8($text); |
| 32 | 32 | throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle text."); |
| 33 | 33 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @param string $text |
| 39 | 39 | */ |
| 40 | - protected function onText_CheckUtf8 (string $text): void { |
|
| 40 | + protected function onText_CheckUtf8(string $text): void { |
|
| 41 | 41 | if (!mb_detect_encoding($text, 'UTF-8', true)) { |
| 42 | 42 | throw new WebSocketError(Frame::CLOSE_BAD_DATA, "Received TEXT is not UTF-8."); |
| 43 | 43 | } |