@@ -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 | } |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | protected $maxLength = 10 * 1024 * 1024; |
| 48 | 48 | |
| 49 | - public function __construct (WebSocketClient $client) { |
|
| 49 | + public function __construct(WebSocketClient $client) { |
|
| 50 | 50 | $this->client = $client; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @return Frame|null |
| 55 | 55 | */ |
| 56 | - protected function getFrame () { |
|
| 56 | + protected function getFrame() { |
|
| 57 | 57 | if (!$this->head) { |
| 58 | 58 | if (preg_match(self::REGEXP, $this->buffer, $head)) { |
| 59 | 59 | [, $op, $len] = unpack('C2', $head[0]); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @return Generator|Frame[] |
| 97 | 97 | */ |
| 98 | - public function getFrames () { |
|
| 98 | + public function getFrames() { |
|
| 99 | 99 | $this->buffer .= $this->client->recvAll(); |
| 100 | 100 | while ($frame = $this->getFrame()) { |
| 101 | 101 | yield $frame; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | /** |
| 106 | 106 | * @return int |
| 107 | 107 | */ |
| 108 | - public function getMaxLength (): int { |
|
| 108 | + public function getMaxLength(): int { |
|
| 109 | 109 | return $this->maxLength; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param int $bytes |
| 114 | 114 | * @return $this |
| 115 | 115 | */ |
| 116 | - public function setMaxLength (int $bytes) { |
|
| 116 | + public function setMaxLength(int $bytes) { |
|
| 117 | 117 | if ($bytes < self::MAX_LENGTH_RANGE[0] or $bytes > self::MAX_LENGTH_RANGE[1]) { |
| 118 | 118 | throw new InvalidArgumentException('Max length must be within range [125,2^63-1]'); |
| 119 | 119 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @throws WebSocketError |
| 128 | 128 | */ |
| 129 | - protected function validate (): void { |
|
| 129 | + protected function validate(): void { |
|
| 130 | 130 | if ($this->head['length'] > $this->maxLength) { |
| 131 | 131 | throw new WebSocketError(Frame::CLOSE_TOO_LARGE, "Payload would exceed {$this->maxLength} bytes"); |
| 132 | 132 | } |
@@ -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->getSockName()); |
| 24 | 24 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @return $this |
| 41 | 41 | * @throws SocketError |
| 42 | 42 | */ |
| 43 | - public function bind (string $address, int $port = 0) { |
|
| 43 | + public function bind(string $address, int $port = 0) { |
|
| 44 | 44 | if (!@socket_bind($this->resource, $address, $port)) { |
| 45 | 45 | throw new SocketError($this->resource, SOCKET_EOPNOTSUPP); |
| 46 | 46 | } |
@@ -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 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @return StreamClient |
| 26 | 26 | * @throws SocketError |
| 27 | 27 | */ |
| 28 | - public function accept () { |
|
| 28 | + public function accept() { |
|
| 29 | 29 | if (!$resource = @socket_accept($this->resource)) { |
| 30 | 30 | throw new SocketError($this->resource); // reliable errno |
| 31 | 31 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @return $this |
| 46 | 46 | * @throws SocketError |
| 47 | 47 | */ |
| 48 | - public function listen (int $backlog = 0) { |
|
| 48 | + public function listen(int $backlog = 0) { |
|
| 49 | 49 | if (!@socket_listen($this->resource, $backlog)) { |
| 50 | 50 | throw new SocketError($this->resource); // reliable errno |
| 51 | 51 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param resource $resource The accepted connection. |
| 59 | 59 | * @return StreamClient |
| 60 | 60 | */ |
| 61 | - protected function newClient ($resource) { |
|
| 61 | + protected function newClient($resource) { |
|
| 62 | 62 | return new StreamClient($resource); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -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_DGRAM; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | * @return string |
| 29 | 29 | * @throws SocketError |
| 30 | 30 | */ |
| 31 | - public function recv (int $length, int $flags = 0, string &$name = null, int &$port = 0): string { |
|
| 31 | + public function recv(int $length, int $flags = 0, string &$name = null, int &$port = 0): string { |
|
| 32 | 32 | $count = @socket_recvfrom($this->resource, $data, $length, $flags, $name, $port); |
| 33 | 33 | if ($count === false) { |
| 34 | 34 | throw new SocketError($this->resource, SOCKET_EOPNOTSUPP); |
| 35 | 35 | } |
| 36 | - return (string)$data; // cast needed, will be null if 0 bytes are read |
|
| 36 | + return (string) $data; // cast needed, will be null if 0 bytes are read |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | \ No newline at end of file |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | * @return int |
| 29 | 29 | * @throws SocketError |
| 30 | 30 | */ |
| 31 | - public static function select (array &$read, array &$write, array &$except, ?float $timeout = null): int { |
|
| 31 | + public static function select(array &$read, array &$write, array &$except, ?float $timeout = null): int { |
|
| 32 | 32 | $rwe = [$read, $write, $except]; |
| 33 | 33 | array_walk_recursive($rwe, function(SocketInterface &$each) { |
| 34 | 34 | $each = $each->getResource(); |
| 35 | 35 | }); |
| 36 | - $uSec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null |
|
| 36 | + $uSec = (int) (fmod($timeout, 1) * 1000000); // ignored if timeout is null |
|
| 37 | 37 | $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $uSec); // keys are preserved |
| 38 | 38 | if ($count === false) { |
| 39 | 39 | $read = $write = $except = []; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param ReactiveInterface $socket |
| 52 | 52 | * @return $this |
| 53 | 53 | */ |
| 54 | - public function add (ReactiveInterface $socket) { |
|
| 54 | + public function add(ReactiveInterface $socket) { |
|
| 55 | 55 | $this->sockets[$socket->getId()] = $socket; |
| 56 | 56 | return $this; |
| 57 | 57 | } |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return int |
| 63 | 63 | */ |
| 64 | - public function count () { |
|
| 64 | + public function count() { |
|
| 65 | 65 | return count($this->sockets); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @return SocketInterface[] |
| 70 | 70 | */ |
| 71 | - public function getSockets () { |
|
| 71 | + public function getSockets() { |
|
| 72 | 72 | return $this->sockets; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param float|null $timeout Maximum seconds to block. `NULL` blocks forever. |
| 83 | 83 | * @return int Number of sockets selected. |
| 84 | 84 | */ |
| 85 | - public function react (?float $timeout = null): int { |
|
| 85 | + public function react(?float $timeout = null): int { |
|
| 86 | 86 | /** @var ReactiveInterface[][] $rwe */ |
| 87 | 87 | $rwe = [$this->sockets, [], $this->sockets]; |
| 88 | 88 | $count = static::select($rwe[0], $rwe[1], $rwe[2], $timeout); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param int|ReactiveInterface $id |
| 111 | 111 | * @return $this |
| 112 | 112 | */ |
| 113 | - public function remove ($id) { |
|
| 113 | + public function remove($id) { |
|
| 114 | 114 | unset($this->sockets[$id instanceof ReactiveInterface ? $id->getId() : $id]); |
| 115 | 115 | return $this; |
| 116 | 116 | } |
@@ -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 { |
@@ -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 | } |
@@ -41,15 +41,15 @@ discard block |
||
| 41 | 41 | 0x0f => 'RESERVED CONTROL 0x0f', |
| 42 | 42 | ]; |
| 43 | 43 | |
| 44 | - const CLOSE_NORMAL = 1000; // mutual closure |
|
| 45 | - const CLOSE_INTERRUPT = 1001; // abrupt closure due to hangups, reboots, "going away" |
|
| 46 | - const CLOSE_PROTOCOL_ERROR = 1002; // invalid behavior / framing |
|
| 47 | - const CLOSE_UNHANDLED_DATA = 1003; // message handler doesn't want the payload |
|
| 48 | - const CLOSE_BAD_DATA = 1007; // message handler can't understand the payload |
|
| 49 | - const CLOSE_POLICY_VIOLATION = 1008; // generic "access denied" |
|
| 50 | - const CLOSE_TOO_LARGE = 1009; // unacceptable payload size |
|
| 51 | - const CLOSE_EXPECTATION = 1010; // peer closed because it wants extensions (listed in the reason) |
|
| 52 | - const CLOSE_INTERNAL_ERROR = 1011; // like http 500 |
|
| 44 | + const CLOSE_NORMAL = 1000; // mutual closure |
|
| 45 | + const CLOSE_INTERRUPT = 1001; // abrupt closure due to hangups, reboots, "going away" |
|
| 46 | + const CLOSE_PROTOCOL_ERROR = 1002; // invalid behavior / framing |
|
| 47 | + const CLOSE_UNHANDLED_DATA = 1003; // message handler doesn't want the payload |
|
| 48 | + const CLOSE_BAD_DATA = 1007; // message handler can't understand the payload |
|
| 49 | + const CLOSE_POLICY_VIOLATION = 1008; // generic "access denied" |
|
| 50 | + const CLOSE_TOO_LARGE = 1009; // unacceptable payload size |
|
| 51 | + const CLOSE_EXPECTATION = 1010; // peer closed because it wants extensions (listed in the reason) |
|
| 52 | + const CLOSE_INTERNAL_ERROR = 1011; // like http 500 |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * @var bool |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param int $opCode |
| 80 | 80 | * @param string $payload |
| 81 | 81 | */ |
| 82 | - public function __construct (bool $final, int $rsv, int $opCode, string $payload) { |
|
| 82 | + public function __construct(bool $final, int $rsv, int $opCode, string $payload) { |
|
| 83 | 83 | $this->final = $final; |
| 84 | 84 | $this->rsv = $rsv; |
| 85 | 85 | $this->opCode = $opCode; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | - public function __toString () { |
|
| 94 | + public function __toString() { |
|
| 95 | 95 | if ($this->isClose()) { |
| 96 | 96 | return $this->getCloseReason(); |
| 97 | 97 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return int |
| 107 | 107 | */ |
| 108 | - final public function getCloseCode (): int { |
|
| 108 | + final public function getCloseCode(): int { |
|
| 109 | 109 | $code = substr($this->payload, 0, 2); |
| 110 | 110 | return isset($code[1]) ? unpack('n', $code)[1] : self::CLOSE_NORMAL; |
| 111 | 111 | } |
@@ -117,126 +117,126 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @return string |
| 119 | 119 | */ |
| 120 | - final public function getCloseReason (): string { |
|
| 120 | + final public function getCloseReason(): string { |
|
| 121 | 121 | return substr($this->payload, 2); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * @return int |
| 126 | 126 | */ |
| 127 | - final public function getLength (): int { |
|
| 127 | + final public function getLength(): int { |
|
| 128 | 128 | return strlen($this->payload); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - public function getName (): string { |
|
| 134 | + public function getName(): string { |
|
| 135 | 135 | return self::NAMES[$this->opCode]; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * @return int |
| 140 | 140 | */ |
| 141 | - final public function getOpCode (): int { |
|
| 141 | + final public function getOpCode(): int { |
|
| 142 | 142 | return $this->opCode; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * @return string |
| 147 | 147 | */ |
| 148 | - final public function getPayload (): string { |
|
| 148 | + final public function getPayload(): string { |
|
| 149 | 149 | return $this->payload; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | 153 | * @return int |
| 154 | 154 | */ |
| 155 | - final public function getRsv (): int { |
|
| 155 | + final public function getRsv(): int { |
|
| 156 | 156 | return $this->rsv; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * @return bool |
| 161 | 161 | */ |
| 162 | - final public function hasRsv1 (): bool { |
|
| 163 | - return (bool)($this->rsv & self::RSV1); |
|
| 162 | + final public function hasRsv1(): bool { |
|
| 163 | + return (bool) ($this->rsv & self::RSV1); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * @return bool |
| 168 | 168 | */ |
| 169 | - final public function hasRsv2 (): bool { |
|
| 170 | - return (bool)($this->rsv & self::RSV2); |
|
| 169 | + final public function hasRsv2(): bool { |
|
| 170 | + return (bool) ($this->rsv & self::RSV2); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | 174 | * @return bool |
| 175 | 175 | */ |
| 176 | - final public function hasRsv3 (): bool { |
|
| 177 | - return (bool)($this->rsv & self::RSV3); |
|
| 176 | + final public function hasRsv3(): bool { |
|
| 177 | + return (bool) ($this->rsv & self::RSV3); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * @return bool |
| 182 | 182 | */ |
| 183 | - final public function isBinary (): bool { |
|
| 183 | + final public function isBinary(): bool { |
|
| 184 | 184 | return $this->opCode === self::OP_BINARY; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * @return bool |
| 189 | 189 | */ |
| 190 | - final public function isClose (): bool { |
|
| 190 | + final public function isClose(): bool { |
|
| 191 | 191 | return $this->opCode === self::OP_CLOSE; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | 195 | * @return bool |
| 196 | 196 | */ |
| 197 | - final public function isContinue (): bool { |
|
| 197 | + final public function isContinue(): bool { |
|
| 198 | 198 | return $this->opCode === self::OP_CONTINUE; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * @return bool |
| 203 | 203 | */ |
| 204 | - final public function isControl (): bool { |
|
| 204 | + final public function isControl(): bool { |
|
| 205 | 205 | return $this->opCode >= self::OP_CLOSE; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | 209 | * @return bool |
| 210 | 210 | */ |
| 211 | - final public function isData (): bool { |
|
| 211 | + final public function isData(): bool { |
|
| 212 | 212 | return $this->opCode < self::OP_CLOSE; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * @return bool |
| 217 | 217 | */ |
| 218 | - final public function isFinal (): bool { |
|
| 218 | + final public function isFinal(): bool { |
|
| 219 | 219 | return $this->final; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * @return bool |
| 224 | 224 | */ |
| 225 | - final public function isPing (): bool { |
|
| 225 | + final public function isPing(): bool { |
|
| 226 | 226 | return $this->opCode === self::OP_PING; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | 230 | * @return bool |
| 231 | 231 | */ |
| 232 | - final public function isPong (): bool { |
|
| 232 | + final public function isPong(): bool { |
|
| 233 | 233 | return $this->opCode === self::OP_PONG; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | 237 | * @return bool |
| 238 | 238 | */ |
| 239 | - final public function isText (): bool { |
|
| 239 | + final public function isText(): bool { |
|
| 240 | 240 | return $this->opCode === self::OP_TEXT; |
| 241 | 241 | } |
| 242 | 242 | |