From 9b44b8f9920e3ad24c8a45844cd8c47ea59d111b Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Fri, 22 Dec 2023 23:12:39 -0800 Subject: [PATCH 1/4] bring Swoole Library to latest --- ext-src/php_swoole_library.h | 2390 +++++++++++++++------------------- 1 file changed, 1032 insertions(+), 1358 deletions(-) diff --git a/ext-src/php_swoole_library.h b/ext-src/php_swoole_library.h index 3e91e7e28bf..7afaf25c74d 100644 --- a/ext-src/php_swoole_library.h +++ b/ext-src/php_swoole_library.h @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dbc08c8d8bc7414dc844d654ce341c516308217f */ +/* $Id: 0ecf1907ff52f1b37c06a13898c816b59a6c1ac2 */ #ifndef SWOOLE_LIBRARY_H #define SWOOLE_LIBRARY_H @@ -632,19 +632,13 @@ static const char* swoole_library_source_core_string_object = "\n" "namespace Swoole;\n" "\n" - "class StringObject\n" + "class StringObject implements \\Stringable\n" "{\n" " /**\n" - " * @var string\n" - " */\n" - " protected $string;\n" - "\n" - " /**\n" " * StringObject constructor.\n" " */\n" - " public function __construct(string $string = '')\n" + " public function __construct(protected string $string = '')\n" " {\n" - " $this->string = $string;\n" " }\n" "\n" " public function __toString(): string\n" @@ -652,9 +646,9 @@ static const char* swoole_library_source_core_string_object = " return $this->string;\n" " }\n" "\n" - " public static function from(string $string = ''): self\n" + " public static function from(string $string = ''): static\n" " {\n" - " return new static($string);\n" + " return new static($string); // @phpstan-ignore new.static\n" " }\n" "\n" " public function length(): int\n" @@ -662,44 +656,29 @@ static const char* swoole_library_source_core_string_object = " return strlen($this->string);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function indexOf(string $needle, int $offset = 0)\n" + " public function indexOf(string $needle, int $offset = 0): false|int\n" " {\n" - " return strpos($this->string, ...func_get_args());\n" + " return strpos($this->string, $needle, $offset);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function lastIndexOf(string $needle, int $offset = 0)\n" + " public function lastIndexOf(string $needle, int $offset = 0): false|int\n" " {\n" - " return strrpos($this->string, ...func_get_args());\n" + " return strrpos($this->string, $needle, $offset);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function pos(string $needle, int $offset = 0)\n" + " public function pos(string $needle, int $offset = 0): false|int\n" " {\n" - " return strpos($this->string, ...func_get_args());\n" + " return strpos($this->string, $needle, $offset);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function rpos(string $needle, int $offset = 0)\n" + " public function rpos(string $needle, int $offset = 0): false|int\n" " {\n" - " return strrpos($this->string, ...func_get_args());\n" + " return strrpos($this->string, $needle, $offset);\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function reverse(): self\n" + " public function reverse(): static\n" " {\n" - " return new static(strrev($this->string));\n" + " return new static(strrev($this->string)); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" @@ -710,32 +689,22 @@ static const char* swoole_library_source_core_string_object = " return stripos($this->string, $needle);\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function lower(): self\n" + " public function lower(): static\n" " {\n" - " return new static(strtolower($this->string));\n" + " return new static(strtolower($this->string)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function upper(): self\n" + " public function upper(): static\n" " {\n" - " return new static(strtoupper($this->string));\n" + " return new static(strtoupper($this->string)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @param mixed $characters\n" - " * @return static\n" - " */\n" - " public function trim($characters = ''): self\n" + " public function trim(string $characters = ''): static\n" " {\n" " if ($characters) {\n" - " return new static(trim($this->string, $characters));\n" + " return new static(trim($this->string, $characters)); // @phpstan-ignore new.static\n" " }\n" - " return new static(trim($this->string));\n" + " return new static(trim($this->string)); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" @@ -743,7 +712,7 @@ static const char* swoole_library_source_core_string_object = " */\n" " public function ltrim(): self\n" " {\n" - " return new static(ltrim($this->string));\n" + " return new static(ltrim($this->string)); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" @@ -751,7 +720,7 @@ static const char* swoole_library_source_core_string_object = " */\n" " public function rtrim(): self\n" " {\n" - " return new static(rtrim($this->string));\n" + " return new static(rtrim($this->string)); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" @@ -759,38 +728,30 @@ static const char* swoole_library_source_core_string_object = " */\n" " public function substr(int $offset, ?int $length = null)\n" " {\n" - " return new static(substr($this->string, ...func_get_args()));\n" + " return new static(substr($this->string, ...func_get_args())); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function repeat(int $times): self\n" + " public function repeat(int $times): static\n" " {\n" - " return new static(str_repeat($this->string, $times));\n" + " return new static(str_repeat($this->string, $times)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @param mixed $str\n" - " * @return static\n" - " */\n" - " public function append($str): self\n" + " public function append(mixed $str): static\n" " {\n" - " return new static($this->string .= $str);\n" + " return new static($this->string .= $str); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" - " * @param null|int $count\n" - " * @return static\n" + " * @param int|null $count\n" " */\n" - " public function replace(string $search, string $replace, &$count = null): self\n" + " public function replace(string $search, string $replace, &$count = null): static\n" " {\n" - " return new static(str_replace($search, $replace, $this->string, $count));\n" + " return new static(str_replace($search, $replace, $this->string, $count)); // @phpstan-ignore new.static\n" " }\n" "\n" " public function startsWith(string $needle): bool\n" " {\n" - " return strpos($this->string, $needle) === 0;\n" + " return str_starts_with($this->string, $needle);\n" " }\n" "\n" " public function endsWith(string $needle): bool\n" @@ -811,7 +772,7 @@ static const char* swoole_library_source_core_string_object = "\n" " public function contains(string $subString): bool\n" " {\n" - " return strpos($this->string, $subString) !== false;\n" + " return str_contains($this->string, $subString);\n" " }\n" "\n" " public function split(string $delimiter, int $limit = PHP_INT_MAX): ArrayObject\n" @@ -827,12 +788,9 @@ static const char* swoole_library_source_core_string_object = " return $this->string[$index];\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function chunkSplit(int $chunkLength = 76, string $chunkEnd = ''): self\n" + " public function chunkSplit(int $chunkLength = 76, string $chunkEnd = ''): static\n" " {\n" - " return new static(chunk_split($this->string, ...func_get_args()));\n" + " return new static(chunk_split($this->string, ...func_get_args())); // @phpstan-ignore new.static\n" " }\n" "\n" " public function chunk(int $splitLength = 1): ArrayObject\n" @@ -872,54 +830,45 @@ static const char* swoole_library_source_core_multibyte_string_object = " return mb_strlen($this->string);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function indexOf(string $needle, int $offset = 0, ?string $encoding = null)\n" + " public function indexOf(string $needle, int $offset = 0, ?string $encoding = null): false|int\n" " {\n" - " return mb_strpos($this->string, ...func_get_args());\n" + " return mb_strpos($this->string, $needle, $offset, $encoding);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function lastIndexOf(string $needle, int $offset = 0, ?string $encoding = null)\n" + " public function lastIndexOf(string $needle, int $offset = 0, ?string $encoding = null): false|int\n" " {\n" - " return mb_strrpos($this->string, ...func_get_args());\n" + " return mb_strrpos($this->string, $needle, $offset, $encoding);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function pos(string $needle, int $offset = 0, ?string $encoding = null)\n" + " public function pos(string $needle, int $offset = 0, ?string $encoding = null): false|int\n" " {\n" - " return mb_strpos($this->string, ...func_get_args());\n" + " return mb_strpos($this->string, $needle, $offset, $encoding);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function rpos(string $needle, int $offset = 0, ?string $encoding = null)\n" + " public function rpos(string $needle, int $offset = 0, ?string $encoding = null): false|int\n" " {\n" - " return mb_strrpos($this->string, ...func_get_args());\n" + " return mb_strrpos($this->string, $needle, $offset, $encoding);\n" " }\n" "\n" - " /**\n" - " * @return false|int\n" - " */\n" - " public function ipos(string $needle, ?string $encoding = null)\n" + " public function ipos(string $needle, int $offset = 0, ?string $encoding = null): int|false\n" " {\n" - " return mb_stripos($this->string, ...func_get_args());\n" + " return mb_stripos($this->string, $needle, $offset, $encoding);\n" " }\n" "\n" " /**\n" - " * @return static\n" + " * @todo First parameter will be renamed to $start in Swoole 5.2+.\n" + " * @todo This method will be refactored and marked as final in Swoole 5.2+.\n" + " * 1. It should use keyword self instead of static.\n" + " * 2. Don't use function func_get_args().\n" " */\n" - " public function substr(int $offset, ?int $length = null, ?string $encoding = null)\n" + " public function substr(int $offset, ?int $length = null, ?string $encoding = null): static\n" " {\n" - " return new static(mb_substr($this->string, ...func_get_args()));\n" + " return new static(mb_substr($this->string, ...func_get_args())); // @phpstan-ignore new.static\n" " }\n" "\n" + " /**\n" + " * @todo This method is not implemented correctly.\n" + " */\n" " public function chunk(int $splitLength = 1, ?int $limit = null): ArrayObject\n" " {\n" " return static::detectArrayType(mb_split($this->string, ...func_get_args()));\n" @@ -990,9 +939,9 @@ static const char* swoole_library_source_core_array_object = " $this->array = $data;\n" " }\n" "\n" - " public static function from(array $array = []): self\n" + " public static function from(array $array = []): static\n" " {\n" - " return new static($array);\n" + " return new static($array); // @phpstan-ignore new.static\n" " }\n" "\n" " public function toArray(): array\n" @@ -1052,10 +1001,9 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @param mixed $key\n" " * @return ArrayObject|StringObject\n" " */\n" - " public function get($key)\n" + " public function get(mixed $key)\n" " {\n" " if (!$this->exists($key)) {\n" " throw new ArrayKeyNotExists($key);\n" @@ -1064,11 +1012,9 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @param mixed $key\n" - " * @param mixed $default\n" " * @return ArrayObject|StringObject\n" " */\n" - " public function getOr($key, $default = null)\n" + " public function getOr(mixed $key, mixed $default = null)\n" " {\n" " if (!$this->exists($key)) {\n" " return $default;\n" @@ -1089,7 +1035,7 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @return null|int|string\n" + " * @return int|string|null\n" " */\n" " public function firstKey()\n" " {\n" @@ -1097,7 +1043,7 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @return null|int|string\n" + " * @return int|string|null\n" " */\n" " public function lastKey()\n" " {\n" @@ -1117,31 +1063,27 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @param mixed $key\n" - " * @param mixed $value\n" " * @return $this\n" " */\n" - " public function set($key, $value): self\n" + " public function set(mixed $key, mixed $value): self\n" " {\n" " $this->array[$key] = $value;\n" " return $this;\n" " }\n" "\n" " /**\n" - " * @param mixed $key\n" " * @return $this\n" " */\n" - " public function delete($key): self\n" + " public function delete(mixed $key): self\n" " {\n" " unset($this->array[$key]);\n" " return $this;\n" " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @return $this\n" " */\n" - " public function remove($value, bool $strict = true, bool $loop = false): self\n" + " public function remove(mixed $value, bool $strict = true, bool $loop = false): self\n" " {\n" " do {\n" " $key = $this->search($value, $strict);\n" @@ -1164,11 +1106,10 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @param mixed $key\n" - " * @return null|mixed\n" + " * @return mixed|null\n" " */\n" " #[\\ReturnTypeWillChange]\n" - " public function offsetGet($key)\n" + " public function offsetGet(mixed $key)\n" " {\n" " if (!array_key_exists($key, $this->array)) {\n" " return null;\n" @@ -1176,63 +1117,47 @@ static const char* swoole_library_source_core_array_object = " return $this->array[$key];\n" " }\n" "\n" - " /**\n" - " * @param mixed $key\n" - " * @param mixed $value\n" - " */\n" - " public function offsetSet($key, $value): void\n" + " public function offsetSet(mixed $key, mixed $value): void\n" " {\n" " $this->array[$key] = $value;\n" " }\n" "\n" - " /**\n" - " * @param mixed $key\n" - " */\n" - " public function offsetUnset($key): void\n" + " public function offsetUnset(mixed $key): void\n" " {\n" " unset($this->array[$key]);\n" " }\n" "\n" " /**\n" - " * @param mixed $key\n" " * @return bool\n" " */\n" " #[\\ReturnTypeWillChange]\n" - " public function offsetExists($key)\n" + " public function offsetExists(mixed $key)\n" " {\n" " return isset($this->array[$key]);\n" " }\n" "\n" - " /**\n" - " * @param mixed $key\n" - " */\n" - " public function exists($key): bool\n" + " public function exists(mixed $key): bool\n" " {\n" " return array_key_exists($key, $this->array);\n" " }\n" "\n" - " /**\n" - " * @param mixed $value\n" - " */\n" - " public function contains($value, bool $strict = true): bool\n" + " public function contains(mixed $value, bool $strict = true): bool\n" " {\n" " return in_array($value, $this->array, $strict);\n" " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @return mixed\n" " */\n" - " public function indexOf($value, bool $strict = true)\n" + " public function indexOf(mixed $value, bool $strict = true)\n" " {\n" " return $this->search($value, $strict);\n" " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @return mixed\n" " */\n" - " public function lastIndexOf($value, bool $strict = true)\n" + " public function lastIndexOf(mixed $value, bool $strict = true)\n" " {\n" " $array = $this->array;\n" " for (end($array); ($currentKey = key($array)) !== null; prev($array)) {\n" @@ -1248,22 +1173,21 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @param mixed $needle\n" " * @return mixed\n" " */\n" - " public function search($needle, bool $strict = true)\n" + " public function search(mixed $needle, bool $strict = true)\n" " {\n" " return array_search($needle, $this->array, $strict);\n" " }\n" "\n" " public function join(string $glue = ''): StringObject\n" " {\n" - " return static::detectStringType(implode($glue, $this->array));\n" + " return self::detectStringType(implode($glue, $this->array));\n" " }\n" "\n" " public function serialize(): StringObject\n" " {\n" - " return static::detectStringType(serialize($this->array));\n" + " return self::detectStringType(serialize($this->array));\n" " }\n" "\n" " /**\n" @@ -1293,19 +1217,17 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @return int\n" " */\n" - " public function push($value)\n" + " public function push(mixed $value)\n" " {\n" " return $this->pushBack($value);\n" " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @return int\n" " */\n" - " public function pushFront($value)\n" + " public function pushFront(mixed $value)\n" " {\n" " return array_unshift($this->array, $value);\n" " }\n" @@ -1317,19 +1239,17 @@ static const char* swoole_library_source_core_array_object = " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @return int\n" " */\n" - " public function pushBack($value)\n" + " public function pushBack(mixed $value)\n" " {\n" " return array_push($this->array, $value);\n" " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @return $this\n" " */\n" - " public function insert(int $offset, $value): self\n" + " public function insert(int $offset, mixed $value): self\n" " {\n" " if (is_array($value) || is_object($value) || is_null($value)) {\n" " $value = [$value];\n" @@ -1362,14 +1282,9 @@ static const char* swoole_library_source_core_array_object = " return array_pop($this->array);\n" " }\n" "\n" - " /**\n" - " * @param mixed $offset\n" - " * @param int $length\n" - " * @return static\n" - " */\n" - " public function slice($offset, int $length = null, bool $preserve_keys = false): self\n" + " public function slice(int $offset, ?int $length = null, bool $preserve_keys = false): static\n" " {\n" - " return new static(array_slice($this->array, ...func_get_args()));\n" + " return new static(array_slice($this->array, $offset, $length, $preserve_keys)); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" @@ -1380,24 +1295,19 @@ static const char* swoole_library_source_core_array_object = " return static::detectType($this->array[array_rand($this->array, 1)]);\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function each(callable $fn): self\n" " {\n" - " if (array_walk($this->array, $fn) === false) {\n" - " throw new \\RuntimeException('array_walk() failed');\n" - " }\n" + " array_walk($this->array, $fn);\n" + "\n" " return $this;\n" " }\n" "\n" " /**\n" " * @param array $args\n" - " * @return static\n" " */\n" - " public function map(callable $fn, ...$args): self\n" + " public function map(callable $fn, ...$args): static\n" " {\n" - " return new static(array_map($fn, $this->array, ...$args));\n" + " return new static(array_map($fn, $this->array, ...$args)); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" @@ -1411,76 +1321,54 @@ static const char* swoole_library_source_core_array_object = "\n" " /**\n" " * @param array $args\n" - " * @return static\n" " */\n" - " public function keys(...$args): self\n" + " public function keys(...$args): static\n" " {\n" - " return new static(array_keys($this->array, ...$args));\n" + " return new static(array_keys($this->array, ...$args)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function values(): self\n" + " public function values(): static\n" " {\n" - " return new static(array_values($this->array));\n" + " return new static(array_values($this->array)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @param mixed $column_key\n" - " * @param mixed $index\n" - " * @return static\n" - " */\n" - " public function column($column_key, $index = null): self\n" + " public function column(mixed $column_key, mixed $index = null): static\n" " {\n" - " return new static(array_column($this->array, $column_key, $index));\n" + " return new static(array_column($this->array, $column_key, $index)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function unique(int $sort_flags = SORT_STRING): self\n" + " public function unique(int $sort_flags = SORT_STRING): static\n" " {\n" - " return new static(array_unique($this->array, $sort_flags));\n" + " return new static(array_unique($this->array, $sort_flags)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function reverse(bool $preserve_keys = false): self\n" + " public function reverse(bool $preserve_keys = false): static\n" " {\n" - " return new static(array_reverse($this->array, $preserve_keys));\n" + " return new static(array_reverse($this->array, $preserve_keys)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function chunk(int $size, bool $preserve_keys = false): self\n" + " public function chunk(int $size, bool $preserve_keys = false): static\n" " {\n" - " return new static(array_chunk($this->array, $size, $preserve_keys));\n" + " return new static(array_chunk($this->array, $size, $preserve_keys)); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" " * Swap keys and values in an array.\n" - " * @return static\n" " */\n" - " public function flip(): self\n" + " public function flip(): static\n" " {\n" - " return new static(array_flip($this->array));\n" + " return new static(array_flip($this->array)); // @phpstan-ignore new.static\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " public function filter(callable $fn, int $flag = 0): self\n" + " public function filter(callable $fn, int $flag = 0): static\n" " {\n" - " return new static(array_filter($this->array, $fn, $flag));\n" + " return new static(array_filter($this->array, $fn, $flag)); // @phpstan-ignore new.static\n" " }\n" "\n" " /**\n" " * | Function name | Sorts by | Maintains key association | Order of sort | Related functions |\n" " * | :---------------- | :------- | :-------------------------- | :-------------------------- | :---------------- |\n" - " * | array_multisort() | value | associative yes, numeric no | first array or sort options | array_walk() |\n" + " * | array_multisort() | value | associative yes, numeric no | first array or sort options | array_walk() |\n" " * | asort() | value | yes | low to high | arsort() |\n" " * | arsort() | value | yes | high to low | asort() |\n" " * | krsort() | key | yes | high to low | ksort() |\n" @@ -1488,11 +1376,11 @@ static const char* swoole_library_source_core_array_object = " * | natcasesort() | value | yes | natural, case insensitive | natsort() |\n" " * | natsort() | value | yes | natural | natcasesort() |\n" " * | rsort() | value | no | high to low | sort() |\n" - " * | shuffle() | value | no | random | array_rand() |\n" + " * | shuffle() | value | no | random | array_rand() |\n" " * | sort() | value | no | low to high | rsort() |\n" - " * | uasort() | value | yes | user defined | uksort() |\n" - " * | uksort() | key | yes | user defined | uasort() |\n" - " * | usort() | value | no | user defined | uasort() |\n" + " * | uasort() | value | yes | user defined | uksort() |\n" + " * | uksort() | key | yes | user defined | uasort() |\n" + " * | usort() | value | no | user defined | uasort() |\n" " */\n" "\n" " /**\n" @@ -1500,42 +1388,29 @@ static const char* swoole_library_source_core_array_object = " */\n" " public function asort(int $sort_flags = SORT_REGULAR): self\n" " {\n" - " if (asort($this->array, $sort_flags) !== true) {\n" - " throw new \\RuntimeException('asort() failed');\n" - " }\n" + " asort($this->array, $sort_flags);\n" + "\n" " return $this;\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function arsort(int $sort_flags = SORT_REGULAR): self\n" " {\n" - " if (arsort($this->array, $sort_flags) !== true) {\n" - " throw new \\RuntimeException('arsort() failed');\n" - " }\n" + " arsort($this->array, $sort_flags);\n" + "\n" " return $this;\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function krsort(int $sort_flags = SORT_REGULAR): self\n" " {\n" - " if (krsort($this->array, $sort_flags) !== true) {\n" - " throw new \\RuntimeException('krsort() failed');\n" - " }\n" + " krsort($this->array, $sort_flags);\n" + "\n" " return $this;\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function ksort(int $sort_flags = SORT_REGULAR): self\n" " {\n" - " if (ksort($this->array, $sort_flags) !== true) {\n" - " throw new \\RuntimeException('ksort() failed');\n" - " }\n" + " ksort($this->array, $sort_flags);\n" + "\n" " return $this;\n" " }\n" "\n" @@ -1572,66 +1447,45 @@ static const char* swoole_library_source_core_array_object = " return $this;\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function shuffle(): self\n" " {\n" - " if (shuffle($this->array) !== true) {\n" - " throw new \\RuntimeException('shuffle() failed');\n" - " }\n" + " shuffle($this->array);\n" + "\n" " return $this;\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function sort(int $sort_flags = SORT_REGULAR): self\n" " {\n" - " if (sort($this->array, $sort_flags) !== true) {\n" - " throw new \\RuntimeException('sort() failed');\n" - " }\n" + " sort($this->array, $sort_flags);\n" + "\n" " return $this;\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function uasort(callable $value_compare_func): self\n" " {\n" - " if (uasort($this->array, $value_compare_func) !== true) {\n" - " throw new \\RuntimeException('uasort() failed');\n" - " }\n" + " uasort($this->array, $value_compare_func);\n" + "\n" " return $this;\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function uksort(callable $value_compare_func): self\n" " {\n" - " if (uksort($this->array, $value_compare_func) !== true) {\n" - " throw new \\RuntimeException('uksort() failed');\n" - " }\n" + " uksort($this->array, $value_compare_func);\n" + "\n" " return $this;\n" " }\n" "\n" - " /**\n" - " * @return $this\n" - " */\n" " public function usort(callable $value_compare_func): self\n" " {\n" - " if (usort($this->array, $value_compare_func) !== true) {\n" - " throw new \\RuntimeException('usort() failed');\n" - " }\n" + " usort($this->array, $value_compare_func);\n" + "\n" " return $this;\n" " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @return ArrayObject|mixed|StringObject\n" " */\n" - " protected static function detectType($value)\n" + " protected static function detectType(mixed $value)\n" " {\n" " if (is_string($value)) {\n" " return static::detectStringType($value);\n" @@ -1647,12 +1501,9 @@ static const char* swoole_library_source_core_array_object = " return new StringObject($value);\n" " }\n" "\n" - " /**\n" - " * @return static\n" - " */\n" - " protected static function detectArrayType(array $value): self\n" + " protected static function detectArrayType(array $value): static\n" " {\n" - " return new static($value);\n" + " return new static($value); // @phpstan-ignore new.static\n" " }\n" "}\n"; @@ -1737,11 +1588,11 @@ static const char* swoole_library_source_core_coroutine_wait_group = "\n" "class WaitGroup\n" "{\n" - " protected $chan;\n" + " protected Channel $chan;\n" "\n" - " protected $count = 0;\n" + " protected int $count = 0;\n" "\n" - " protected $waiting = false;\n" + " protected bool $waiting = false;\n" "\n" " public function __construct(int $delta = 0)\n" " {\n" @@ -1782,7 +1633,7 @@ static const char* swoole_library_source_core_coroutine_wait_group = " }\n" " if ($this->count > 0) {\n" " $this->waiting = true;\n" - " $done = $this->chan->pop($timeout);\n" + " $done = $this->chan->pop($timeout);\n" " $this->waiting = false;\n" " return $done;\n" " }\n" @@ -1809,13 +1660,11 @@ static const char* swoole_library_source_core_coroutine_server = "\n" "namespace Swoole\\Coroutine;\n" "\n" + "use Swoole\\Constant;\n" "use Swoole\\Coroutine;\n" "use Swoole\\Coroutine\\Server\\Connection;\n" "use Swoole\\Exception;\n" "\n" - "/* compatibility constant */\n" - "define('SWOOLE_COROUTINE_SOCKET_HAVE_SSL_HANDSHAKE', method_exists(Socket::class, 'sslHandshake'));\n" - "\n" "class Server\n" "{\n" " /** @var string */\n" @@ -1839,7 +1688,7 @@ static const char* swoole_library_source_core_coroutine_server = " /** @var bool */\n" " protected $running = false;\n" "\n" - " /** @var null|callable */\n" + " /** @var callable|null */\n" " protected $fn;\n" "\n" " /** @var Socket */\n" @@ -1855,7 +1704,7 @@ static const char* swoole_library_source_core_coroutine_server = " if ($_host->contains('::')) {\n" " $this->type = AF_INET6;\n" " } elseif ($_host->startsWith('unix:/')) {\n" - " $host = $_host->substr(5)->__toString();\n" + " $host = $_host->substr(5)->__toString();\n" " $this->type = AF_UNIX;\n" " } else {\n" " $this->type = AF_INET;\n" @@ -1872,9 +1721,9 @@ static const char* swoole_library_source_core_coroutine_server = " if (!$socket->listen()) {\n" " throw new Exception('listen() failed', $socket->errCode);\n" " }\n" - " $this->port = $socket->getsockname()['port'] ?? 0;\n" - " $this->fd = $socket->fd;\n" - " $this->socket = $socket;\n" + " $this->port = $socket->getsockname()['port'] ?? 0;\n" + " $this->fd = $socket->fd;\n" + " $this->socket = $socket;\n" " $this->setting['open_ssl'] = $ssl;\n" " }\n" "\n" @@ -1913,7 +1762,7 @@ static const char* swoole_library_source_core_coroutine_server = " $conn = $socket->accept();\n" " if ($conn) {\n" " $conn->setProtocol($this->setting);\n" - " if (SWOOLE_COROUTINE_SOCKET_HAVE_SSL_HANDSHAKE && $this->setting['open_ssl'] ?? false) {\n" + " if (!empty($this->setting[Constant::OPTION_OPEN_SSL])) {\n" " $fn = static function ($fn, $connection) {\n" " /* @var $connection Connection */\n" " if (!$connection->exportSocket()->sslHandshake()) {\n" @@ -1923,7 +1772,7 @@ static const char* swoole_library_source_core_coroutine_server = " };\n" " $arguments = [$this->fn, new Connection($conn)];\n" " } else {\n" - " $fn = $this->fn;\n" + " $fn = $this->fn;\n" " $arguments = [new Connection($conn)];\n" " }\n" " if (Coroutine::create($fn, ...$arguments) < 0) {\n" @@ -2016,11 +1865,11 @@ static const char* swoole_library_source_core_coroutine_barrier = "\n" "class Barrier\n" "{\n" - " private $cid = -1;\n" + " private int $cid = -1;\n" "\n" " private $timer = -1;\n" "\n" - " private static $cancel_list = [];\n" + " private static array $cancel_list = [];\n" "\n" " public function __destruct()\n" " {\n" @@ -2038,9 +1887,9 @@ static const char* swoole_library_source_core_coroutine_barrier = " }\n" " }\n" "\n" - " public static function make()\n" + " public static function make(): self\n" " {\n" - " return new static();\n" + " return new self();\n" " }\n" "\n" " /**\n" @@ -2051,7 +1900,7 @@ static const char* swoole_library_source_core_coroutine_barrier = " if ($barrier->cid !== -1) {\n" " throw new Exception('The barrier is waiting, cannot wait again.');\n" " }\n" - " $cid = Coroutine::getCid();\n" + " $cid = Coroutine::getCid();\n" " $barrier->cid = $cid;\n" " if ($timeout > 0 && ($timeout_ms = (int) ($timeout * 1000)) > 0) {\n" " $barrier->timer = Timer::after($timeout_ms, function () use ($cid) {\n" @@ -2084,20 +1933,8 @@ static const char* swoole_library_source_core_coroutine_http_client_proxy = "\n" "class ClientProxy\n" "{\n" - " private $body;\n" - "\n" - " private $statusCode;\n" - "\n" - " private $headers;\n" - "\n" - " private $cookies;\n" - "\n" - " public function __construct($body, $statusCode, $headers, $cookies)\n" + " public function __construct(private $body, private $statusCode, private $headers, private $cookies)\n" " {\n" - " $this->body = $body;\n" - " $this->statusCode = $statusCode;\n" - " $this->headers = $headers;\n" - " $this->cookies = $cookies;\n" " }\n" "\n" " public function getBody()\n" @@ -2138,40 +1975,34 @@ static const char* swoole_library_source_core_coroutine_http_functions = "use Swoole\\Coroutine\\Http\\Client\\Exception;\n" "\n" "/**\n" - " * @param null $data\n" " * @throws Exception\n" " */\n" "function request(\n" " string $url,\n" " string $method,\n" - " $data = null,\n" - " array $options = null,\n" - " array $headers = null,\n" - " array $cookies = null\n" + " mixed $data = null,\n" + " ?array $options = null,\n" + " ?array $headers = null,\n" + " ?array $cookies = null\n" "): ClientProxy {\n" " $driver = swoole_library_get_option('http_client_driver');\n" - " switch ($driver) {\n" - " case 'curl':\n" - " return request_with_curl($url, $method, $data, $options, $headers, $cookies);\n" - " case 'stream':\n" - " return request_with_stream($url, $method, $data, $options, $headers, $cookies);\n" - " case 'swoole':\n" - " default:\n" - " return request_with_http_client($url, $method, $data, $options, $headers, $cookies);\n" - " }\n" + " return match ($driver) {\n" + " 'curl' => request_with_curl($url, $method, $data, $options, $headers, $cookies),\n" + " 'stream' => request_with_stream($url, $method, $data, $options, $headers, $cookies),\n" + " default => request_with_http_client($url, $method, $data, $options, $headers, $cookies),\n" + " };\n" "}\n" "\n" "/**\n" - " * @param mixed $data\n" " * @throws Exception\n" " */\n" "function request_with_http_client(\n" " string $url,\n" " string $method,\n" - " $data = null,\n" - " array $options = null,\n" - " array $headers = null,\n" - " array $cookies = null\n" + " mixed $data = null,\n" + " ?array $options = null,\n" + " ?array $headers = null,\n" + " ?array $cookies = null\n" "): ClientProxy {\n" " $info = parse_url($url);\n" " if (empty($info['scheme'])) {\n" @@ -2213,16 +2044,15 @@ static const char* swoole_library_source_core_coroutine_http_functions = "}\n" "\n" "/**\n" - " * @param mixed $data\n" " * @throws Exception\n" " */\n" "function request_with_curl(\n" " string $url,\n" " string $method,\n" - " $data = null,\n" - " array $options = null,\n" - " array $headers = null,\n" - " array $cookies = null\n" + " mixed $data = null,\n" + " ?array $options = null,\n" + " ?array $headers = null,\n" + " ?array $cookies = null\n" "): ClientProxy {\n" " $ch = curl_init($url);\n" " if (empty($ch)) {\n" @@ -2232,14 +2062,14 @@ static const char* swoole_library_source_core_coroutine_http_functions = " curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));\n" " $responseHeaders = $responseCookies = [];\n" " curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $header) use (&$responseHeaders, &$responseCookies) {\n" - " $len = strlen($header);\n" + " $len = strlen($header);\n" " $header = explode(':', $header, 2);\n" " if (count($header) < 2) {\n" " return $len;\n" " }\n" " $headerKey = strtolower(trim($header[0]));\n" " if ($headerKey == 'set-cookie') {\n" - " [$k, $v] = explode('=', $header[1]);\n" + " [$k, $v] = explode('=', $header[1]);\n" " $responseCookies[$k] = $v;\n" " } else {\n" " $responseHeaders[$headerKey][] = trim($header[1]);\n" @@ -2283,16 +2113,15 @@ static const char* swoole_library_source_core_coroutine_http_functions = "}\n" "\n" "/**\n" - " * @param mixed $data\n" " * @throws Exception\n" " */\n" "function request_with_stream(\n" " string $url,\n" " string $method,\n" - " $data = null,\n" - " array $options = null,\n" - " array $headers = null,\n" - " array $cookies = null\n" + " mixed $data = null,\n" + " ?array $options = null,\n" + " ?array $headers = null,\n" + " ?array $cookies = null\n" "): ClientProxy {\n" " $stream_options = [\n" " 'http' => [\n" @@ -2333,10 +2162,9 @@ static const char* swoole_library_source_core_coroutine_http_functions = "}\n" "\n" "/**\n" - " * @param mixed $data\n" " * @throws Exception\n" " */\n" - "function post(string $url, $data, array $options = null, array $headers = null, array $cookies = null): ClientProxy\n" + "function post(string $url, mixed $data, ?array $options = null, ?array $headers = null, ?array $cookies = null): ClientProxy\n" "{\n" " return request($url, 'POST', $data, $options, $headers, $cookies);\n" "}\n" @@ -2344,7 +2172,7 @@ static const char* swoole_library_source_core_coroutine_http_functions = "/**\n" " * @throws Exception\n" " */\n" - "function get(string $url, array $options = null, array $headers = null, array $cookies = null): ClientProxy\n" + "function get(string $url, ?array $options = null, ?array $headers = null, ?array $cookies = null): ClientProxy\n" "{\n" " return request($url, 'GET', null, $options, $headers, $cookies);\n" "}\n"; @@ -2369,27 +2197,19 @@ static const char* swoole_library_source_core_connection_pool = "{\n" " public const DEFAULT_SIZE = 64;\n" "\n" - " /** @var Channel */\n" - " protected $pool;\n" + " protected ?Channel $pool;\n" "\n" " /** @var callable */\n" " protected $constructor;\n" "\n" - " /** @var int */\n" - " protected $size;\n" + " protected int $size;\n" "\n" - " /** @var int */\n" - " protected $num;\n" + " protected int $num = 0;\n" "\n" - " /** @var null|string */\n" - " protected $proxy;\n" - "\n" - " public function __construct(callable $constructor, int $size = self::DEFAULT_SIZE, ?string $proxy = null)\n" + " public function __construct(callable $constructor, int $size = self::DEFAULT_SIZE, protected ?string $proxy = null)\n" " {\n" - " $this->pool = new Channel($this->size = $size);\n" + " $this->pool = new Channel($this->size = $size);\n" " $this->constructor = $constructor;\n" - " $this->num = 0;\n" - " $this->proxy = $proxy;\n" " }\n" "\n" " public function fill(): void\n" @@ -2428,7 +2248,7 @@ static const char* swoole_library_source_core_connection_pool = " {\n" " $this->pool->close();\n" " $this->pool = null;\n" - " $this->num = 0;\n" + " $this->num = 0;\n" " }\n" "\n" " protected function make(): void\n" @@ -2439,7 +2259,7 @@ static const char* swoole_library_source_core_connection_pool = " $connection = new $this->proxy($this->constructor);\n" " } else {\n" " $constructor = $this->constructor;\n" - " $connection = $constructor();\n" + " $connection = $constructor();\n" " }\n" " } catch (\\Throwable $throwable) {\n" " $this->num--;\n" @@ -2449,7 +2269,7 @@ static const char* swoole_library_source_core_connection_pool = " }\n" "}\n"; -static const char* swoole_library_source_core_database_object_proxy = +static const char* swoole_library_source_core_database_detects_lost_connections = "\n" "/**\n" " * This file is part of Swoole.\n" @@ -2463,11 +2283,70 @@ static const char* swoole_library_source_core_database_object_proxy = "\n" "namespace Swoole\\Database;\n" "\n" - "class ObjectProxy extends \\Swoole\\ObjectProxy\n" + "class DetectsLostConnections\n" "{\n" - " public function __clone()\n" + " private const ERROR_MESSAGES = [\n" + " 'server has gone away',\n" + " 'no connection to the server',\n" + " 'Lost connection',\n" + " 'is dead or not enabled',\n" + " 'Error while sending',\n" + " 'decryption failed or bad record mac',\n" + " 'server closed the connection unexpectedly',\n" + " 'SSL connection has been closed unexpectedly',\n" + " 'Error writing data to the connection',\n" + " 'Resource deadlock avoided',\n" + " 'Transaction() on null',\n" + " 'child connection forced to terminate due to client_idle_limit',\n" + " 'query_wait_timeout',\n" + " 'reset by peer',\n" + " 'Physical connection is not usable',\n" + " 'TCP Provider: Error code 0x68',\n" + " 'ORA-03113',\n" + " 'ORA-03114',\n" + " 'Packets out of order. Expected',\n" + " 'Adaptive Server connection failed',\n" + " 'Communication link failure',\n" + " 'connection is no longer usable',\n" + " 'Login timeout expired',\n" + " 'SQLSTATE[HY000] [2002] Connection refused',\n" + " 'running with the --read-only option so it cannot execute this statement',\n" + " 'The connection is broken and recovery is not possible. The connection is marked by the client driver as unrecoverable. No attempt was made to restore the connection.',\n" + " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again',\n" + " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known',\n" + " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for',\n" + " 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: EOF detected',\n" + " 'SQLSTATE[HY000] [2002] Connection timed out',\n" + " 'SSL: Connection timed out',\n" + " 'SQLSTATE[HY000]: General error: 1105 The last transaction was aborted due to Seamless Scaling. Please retry.',\n" + " 'Temporary failure in name resolution',\n" + " 'SSL: Broken pipe',\n" + " 'SQLSTATE[08S01]: Communication link failure',\n" + " 'SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host',\n" + " 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: No route to host',\n" + " 'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.',\n" + " 'SQLSTATE[08006] [7] could not translate host name',\n" + " 'TCP Provider: Error code 0x274C',\n" + " 'SQLSTATE[HY000] [2002] No such file or directory',\n" + " 'SSL: Operation timed out',\n" + " 'Reason: Server is in script upgrade mode. Only administrator can connect at this time.',\n" + " 'Unknown $curl_error_code: 77',\n" + " 'SSL: Handshake timed out',\n" + " 'SQLSTATE[08006] [7] SSL error: sslv3 alert unexpected message',\n" + " 'SQLSTATE[08006] [7] unrecognized SSL error code:',\n" + " 'SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it',\n" + " ];\n" + "\n" + " public static function causedByLostConnection(\\Throwable $e): bool\n" " {\n" - " throw new \\Error('Trying to clone an uncloneable database proxy object');\n" + " $message = $e->getMessage();\n" + " foreach (self::ERROR_MESSAGES as $needle) {\n" + " if ($needle !== '' && mb_strpos($message, $needle) !== false) {\n" + " return true;\n" + " }\n" + " }\n" + "\n" + " return false;\n" " }\n" "}\n"; @@ -2493,7 +2372,7 @@ static const char* swoole_library_source_core_database_mysqli_config = " /** @var int */\n" " protected $port = 3306;\n" "\n" - " /** @var null|string */\n" + " /** @var string|null */\n" " protected $unixSocket = '';\n" "\n" " /** @var string */\n" @@ -2641,12 +2520,8 @@ static const char* swoole_library_source_core_database_mysqli_pool = " */\n" "class MysqliPool extends ConnectionPool\n" "{\n" - " /** @var MysqliConfig */\n" - " protected $config;\n" - "\n" - " public function __construct(MysqliConfig $config, int $size = self::DEFAULT_SIZE)\n" + " public function __construct(protected MysqliConfig $config, int $size = self::DEFAULT_SIZE)\n" " {\n" - " $this->config = $config;\n" " parent::__construct(function () {\n" " $mysqli = new \\mysqli();\n" " foreach ($this->config->getOptions() as $option => $value) {\n" @@ -2660,10 +2535,10 @@ static const char* swoole_library_source_core_database_mysqli_pool = " $this->config->getPort(),\n" " $this->config->getUnixSocket()\n" " );\n" - " $mysqli->set_charset($this->config->getCharset());\n" " if ($mysqli->connect_errno) {\n" " throw new MysqliException($mysqli->connect_error, $mysqli->connect_errno);\n" " }\n" + " $mysqli->set_charset($this->config->getCharset());\n" " return $mysqli;\n" " }, $size, MysqliProxy::class);\n" " }\n" @@ -2699,10 +2574,10 @@ static const char* swoole_library_source_core_database_mysqli_proxy = " /** @var string */\n" " protected $charsetContext;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $setOptContext;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $changeUserContext;\n" "\n" " /** @var callable */\n" @@ -2813,16 +2688,16 @@ static const char* swoole_library_source_core_database_mysqli_statement_proxy = " /** @var \\mysqli_stmt */\n" " protected $__object;\n" "\n" - " /** @var null|string */\n" + " /** @var string|null */\n" " protected $queryString;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $attrSetContext;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $bindParamContext;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $bindResultContext;\n" "\n" " /** @var \\Mysqli|MysqliProxy */\n" @@ -2835,7 +2710,7 @@ static const char* swoole_library_source_core_database_mysqli_statement_proxy = " {\n" " parent::__construct($object);\n" " $this->queryString = $queryString;\n" - " $this->parent = $parent;\n" + " $this->parent = $parent;\n" " $this->parentRound = $parent->getRound();\n" " }\n" "\n" @@ -2856,7 +2731,7 @@ static const char* swoole_library_source_core_database_mysqli_statement_proxy = " /* if not equal, parent has reconnected */\n" " $this->parent->reconnect();\n" " }\n" - " $parent = $this->parent->__getObject();\n" + " $parent = $this->parent->__getObject();\n" " $this->__object = $this->queryString ? @$parent->prepare($this->queryString) : @$parent->stmt_init();\n" " if ($this->__object === false) {\n" " throw new MysqliException($parent->error, $parent->errno);\n" @@ -2902,7 +2777,7 @@ static const char* swoole_library_source_core_database_mysqli_statement_proxy = " }\n" "}\n"; -static const char* swoole_library_source_core_database_detects_lost_connections = +static const char* swoole_library_source_core_database_object_proxy = "\n" "/**\n" " * This file is part of Swoole.\n" @@ -2916,72 +2791,11 @@ static const char* swoole_library_source_core_database_detects_lost_connections "\n" "namespace Swoole\\Database;\n" "\n" - "use Throwable;\n" - "\n" - "class DetectsLostConnections\n" + "class ObjectProxy extends \\Swoole\\ObjectProxy\n" "{\n" - " private const ERROR_MESSAGES = [\n" - " 'server has gone away',\n" - " 'no connection to the server',\n" - " 'Lost connection',\n" - " 'is dead or not enabled',\n" - " 'Error while sending',\n" - " 'decryption failed or bad record mac',\n" - " 'server closed the connection unexpectedly',\n" - " 'SSL connection has been closed unexpectedly',\n" - " 'Error writing data to the connection',\n" - " 'Resource deadlock avoided',\n" - " 'Transaction() on null',\n" - " 'child connection forced to terminate due to client_idle_limit',\n" - " 'query_wait_timeout',\n" - " 'reset by peer',\n" - " 'Physical connection is not usable',\n" - " 'TCP Provider: Error code 0x68',\n" - " 'ORA-03113',\n" - " 'ORA-03114',\n" - " 'Packets out of order. Expected',\n" - " 'Adaptive Server connection failed',\n" - " 'Communication link failure',\n" - " 'connection is no longer usable',\n" - " 'Login timeout expired',\n" - " 'SQLSTATE[HY000] [2002] Connection refused',\n" - " 'running with the --read-only option so it cannot execute this statement',\n" - " 'The connection is broken and recovery is not possible. The connection is marked by the client driver as unrecoverable. No attempt was made to restore the connection.',\n" - " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again',\n" - " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known',\n" - " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for',\n" - " 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: EOF detected',\n" - " 'SQLSTATE[HY000] [2002] Connection timed out',\n" - " 'SSL: Connection timed out',\n" - " 'SQLSTATE[HY000]: General error: 1105 The last transaction was aborted due to Seamless Scaling. Please retry.',\n" - " 'Temporary failure in name resolution',\n" - " 'SSL: Broken pipe',\n" - " 'SQLSTATE[08S01]: Communication link failure',\n" - " 'SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host',\n" - " 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: No route to host',\n" - " 'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.',\n" - " 'SQLSTATE[08006] [7] could not translate host name',\n" - " 'TCP Provider: Error code 0x274C',\n" - " 'SQLSTATE[HY000] [2002] No such file or directory',\n" - " 'SSL: Operation timed out',\n" - " 'Reason: Server is in script upgrade mode. Only administrator can connect at this time.',\n" - " 'Unknown $curl_error_code: 77',\n" - " 'SSL: Handshake timed out',\n" - " 'SQLSTATE[08006] [7] SSL error: sslv3 alert unexpected message',\n" - " 'SQLSTATE[08006] [7] unrecognized SSL error code:',\n" - " 'SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it',\n" - " ];\n" - "\n" - " public static function causedByLostConnection(Throwable $e): bool\n" + " final public function __clone(): void\n" " {\n" - " $message = $e->getMessage();\n" - " foreach (self::ERROR_MESSAGES as $needle) {\n" - " if ($needle !== '' && mb_strpos($message, $needle) !== false) {\n" - " return true;\n" - " }\n" - " }\n" - "\n" - " return false;\n" + " throw new \\Error('Trying to clone an uncloneable database proxy object');\n" " }\n" "}\n"; @@ -3012,8 +2826,7 @@ static const char* swoole_library_source_core_database_pdo_config = " /** @var int */\n" " protected $port = 3306;\n" "\n" - " /** @var string */\n" - " protected $unixSocket = '';\n" + " protected string $unixSocket = '';\n" "\n" " /** @var string */\n" " protected $dbname = 'test';\n" @@ -3161,7 +2974,6 @@ static const char* swoole_library_source_core_database_pdo_pool = "\n" "namespace Swoole\\Database;\n" "\n" - "use Exception;\n" "use PDO;\n" "use Swoole\\ConnectionPool;\n" "\n" @@ -3170,22 +2982,15 @@ static const char* swoole_library_source_core_database_pdo_pool = " */\n" "class PDOPool extends ConnectionPool\n" "{\n" - " /** @var int */\n" - " protected $size = 64;\n" - "\n" - " /** @var PDOConfig */\n" - " protected $config;\n" - "\n" - " public function __construct(PDOConfig $config, int $size = self::DEFAULT_SIZE)\n" + " public function __construct(protected PDOConfig $config, int $size = self::DEFAULT_SIZE)\n" " {\n" - " $this->config = $config;\n" " parent::__construct(function () {\n" " $driver = $this->config->getDriver();\n" " if ($driver === 'sqlite') {\n" - " return new PDO($this->createDSN('sqlite'));\n" + " return new \\PDO($this->createDSN('sqlite'));\n" " }\n" "\n" - " return new PDO($this->createDSN($driver), $this->config->getUsername(), $this->config->getPassword(), $this->config->getOptions());\n" + " return new \\PDO($this->createDSN($driver), $this->config->getUsername(), $this->config->getPassword(), $this->config->getOptions());\n" " }, $size, PDOProxy::class);\n" " }\n" "\n" @@ -3199,7 +3004,7 @@ static const char* swoole_library_source_core_database_pdo_pool = "\n" " /**\n" " * @purpose create DSN\n" - " * @throws Exception\n" + " * @throws \\Exception\n" " */\n" " private function createDSN(string $driver): string\n" " {\n" @@ -3221,7 +3026,7 @@ static const char* swoole_library_source_core_database_pdo_pool = " $dsn = 'sqlite:' . $this->config->getDbname();\n" " break;\n" " default:\n" - " throw new Exception('Unsupported Database Driver:' . $driver);\n" + " throw new \\Exception('Unsupported Database Driver:' . $driver);\n" " }\n" " return $dsn;\n" " }\n" @@ -3241,30 +3046,25 @@ static const char* swoole_library_source_core_database_pdo_proxy = "\n" "namespace Swoole\\Database;\n" "\n" - "use PDO;\n" - "use PDOException;\n" - "\n" "class PDOProxy extends ObjectProxy\n" "{\n" - " /** @var PDO */\n" + " /** @var \\PDO */\n" " protected $__object;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $setAttributeContext;\n" "\n" " /** @var callable */\n" " protected $constructor;\n" "\n" - " /** @var int */\n" - " protected $round = 0;\n" + " protected int $round = 0;\n" "\n" - " /** @var int */\n" - " protected $inTransaction = 0;\n" + " protected int $inTransaction = 0;\n" "\n" " public function __construct(callable $constructor)\n" " {\n" " parent::__construct($constructor());\n" - " $this->__object->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n" + " $this->__object->setAttribute(\\PDO::ATTR_ERRMODE, \\PDO::ERRMODE_EXCEPTION);\n" " $this->constructor = $constructor;\n" " }\n" "\n" @@ -3272,7 +3072,7 @@ static const char* swoole_library_source_core_database_pdo_proxy = " {\n" " try {\n" " $ret = $this->__object->{$name}(...$arguments);\n" - " } catch (PDOException $e) {\n" + " } catch (\\PDOException $e) {\n" " if (!$this->__object->inTransaction() && DetectsLostConnections::causedByLostConnection($e)) {\n" " $this->reconnect();\n" " $ret = $this->__object->{$name}(...$arguments);\n" @@ -3305,7 +3105,7 @@ static const char* swoole_library_source_core_database_pdo_proxy = " {\n" " $constructor = $this->constructor;\n" " parent::__construct($constructor());\n" - " $this->__object->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n" + " $this->__object->setAttribute(\\PDO::ATTR_ERRMODE, \\PDO::ERRMODE_EXCEPTION);\n" " $this->round++;\n" " /* restore context */\n" " if ($this->setAttributeContext) {\n" @@ -3346,27 +3146,24 @@ static const char* swoole_library_source_core_database_pdo_statement_proxy = "\n" "namespace Swoole\\Database;\n" "\n" - "use PDOException;\n" - "use PDOStatement;\n" - "\n" "class PDOStatementProxy extends ObjectProxy\n" "{\n" - " /** @var PDOStatement */\n" + " /** @var \\PDOStatement */\n" " protected $__object;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $setAttributeContext;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $setFetchModeContext;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $bindParamContext;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $bindColumnContext;\n" "\n" - " /** @var null|array */\n" + " /** @var array|null */\n" " protected $bindValueContext;\n" "\n" " /** @var \\PDO|PDOProxy */\n" @@ -3375,10 +3172,10 @@ static const char* swoole_library_source_core_database_pdo_statement_proxy = " /** @var int */\n" " protected $parentRound;\n" "\n" - " public function __construct(PDOStatement $object, PDOProxy $parent)\n" + " public function __construct(\\PDOStatement $object, PDOProxy $parent)\n" " {\n" " parent::__construct($object);\n" - " $this->parent = $parent;\n" + " $this->parent = $parent;\n" " $this->parentRound = $parent->getRound();\n" " }\n" "\n" @@ -3386,13 +3183,13 @@ static const char* swoole_library_source_core_database_pdo_statement_proxy = " {\n" " try {\n" " $ret = $this->__object->{$name}(...$arguments);\n" - " } catch (PDOException $e) {\n" + " } catch (\\PDOException $e) {\n" " if (!$this->parent->inTransaction() && DetectsLostConnections::causedByLostConnection($e)) {\n" " if ($this->parent->getRound() === $this->parentRound) {\n" " /* if not equal, parent has reconnected */\n" " $this->parent->reconnect();\n" " }\n" - " $parent = $this->parent->__getObject();\n" + " $parent = $this->parent->__getObject();\n" " $this->__object = $parent->prepare($this->__object->queryString);\n" "\n" " if ($this->setAttributeContext) {\n" @@ -3610,12 +3407,8 @@ static const char* swoole_library_source_core_database_redis_pool = " */\n" "class RedisPool extends ConnectionPool\n" "{\n" - " /** @var RedisConfig */\n" - " protected $config;\n" - "\n" - " public function __construct(RedisConfig $config, int $size = self::DEFAULT_SIZE)\n" + " public function __construct(protected RedisConfig $config, int $size = self::DEFAULT_SIZE)\n" " {\n" - " $this->config = $config;\n" " parent::__construct(function () {\n" " $redis = new \\Redis();\n" " /* Compatible with different versions of Redis extension as much as possible */\n" @@ -3785,66 +3578,66 @@ static const char* swoole_library_source_core_http_status = " public const NETWORK_AUTHENTICATION_REQUIRED = 511;\n" "\n" " protected static $reasonPhrases = [\n" - " self::CONTINUE => 'Continue',\n" - " self::SWITCHING_PROTOCOLS => 'Switching Protocols',\n" - " self::PROCESSING => 'Processing',\n" - " self::OK => 'OK',\n" - " self::CREATED => 'Created',\n" - " self::ACCEPTED => 'Accepted',\n" - " self::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',\n" - " self::NO_CONTENT => 'No Content',\n" - " self::RESET_CONTENT => 'Reset Content',\n" - " self::PARTIAL_CONTENT => 'Partial Content',\n" - " self::MULTI_STATUS => 'Multi-status',\n" - " self::ALREADY_REPORTED => 'Already Reported',\n" - " self::IM_USED => 'IM Used',\n" - " self::MULTIPLE_CHOICES => 'Multiple Choices',\n" - " self::MOVED_PERMANENTLY => 'Moved Permanently',\n" - " self::FOUND => 'Found',\n" - " self::SEE_OTHER => 'See Other',\n" - " self::NOT_MODIFIED => 'Not Modified',\n" - " self::USE_PROXY => 'Use Proxy',\n" - " self::SWITCH_PROXY => 'Switch Proxy',\n" - " self::TEMPORARY_REDIRECT => 'Temporary Redirect',\n" - " self::PERMANENT_REDIRECT => 'Permanent Redirect',\n" - " self::BAD_REQUEST => 'Bad Request',\n" - " self::UNAUTHORIZED => 'Unauthorized',\n" - " self::PAYMENT_REQUIRED => 'Payment Required',\n" - " self::FORBIDDEN => 'Forbidden',\n" - " self::NOT_FOUND => 'Not Found',\n" - " self::METHOD_NOT_ALLOWED => 'Method Not Allowed',\n" - " self::NOT_ACCEPTABLE => 'Not Acceptable',\n" - " self::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',\n" - " self::REQUEST_TIME_OUT => 'Request Time-out',\n" - " self::CONFLICT => 'Conflict',\n" - " self::GONE => 'Gone',\n" - " self::LENGTH_REQUIRED => 'Length Required',\n" - " self::PRECONDITION_FAILED => 'Precondition Failed',\n" - " self::REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large',\n" - " self::REQUEST_URI_TOO_LARGE => 'Request-URI Too Large',\n" - " self::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',\n" + " self::CONTINUE => 'Continue',\n" + " self::SWITCHING_PROTOCOLS => 'Switching Protocols',\n" + " self::PROCESSING => 'Processing',\n" + " self::OK => 'OK',\n" + " self::CREATED => 'Created',\n" + " self::ACCEPTED => 'Accepted',\n" + " self::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',\n" + " self::NO_CONTENT => 'No Content',\n" + " self::RESET_CONTENT => 'Reset Content',\n" + " self::PARTIAL_CONTENT => 'Partial Content',\n" + " self::MULTI_STATUS => 'Multi-status',\n" + " self::ALREADY_REPORTED => 'Already Reported',\n" + " self::IM_USED => 'IM Used',\n" + " self::MULTIPLE_CHOICES => 'Multiple Choices',\n" + " self::MOVED_PERMANENTLY => 'Moved Permanently',\n" + " self::FOUND => 'Found',\n" + " self::SEE_OTHER => 'See Other',\n" + " self::NOT_MODIFIED => 'Not Modified',\n" + " self::USE_PROXY => 'Use Proxy',\n" + " self::SWITCH_PROXY => 'Switch Proxy',\n" + " self::TEMPORARY_REDIRECT => 'Temporary Redirect',\n" + " self::PERMANENT_REDIRECT => 'Permanent Redirect',\n" + " self::BAD_REQUEST => 'Bad Request',\n" + " self::UNAUTHORIZED => 'Unauthorized',\n" + " self::PAYMENT_REQUIRED => 'Payment Required',\n" + " self::FORBIDDEN => 'Forbidden',\n" + " self::NOT_FOUND => 'Not Found',\n" + " self::METHOD_NOT_ALLOWED => 'Method Not Allowed',\n" + " self::NOT_ACCEPTABLE => 'Not Acceptable',\n" + " self::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',\n" + " self::REQUEST_TIME_OUT => 'Request Time-out',\n" + " self::CONFLICT => 'Conflict',\n" + " self::GONE => 'Gone',\n" + " self::LENGTH_REQUIRED => 'Length Required',\n" + " self::PRECONDITION_FAILED => 'Precondition Failed',\n" + " self::REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large',\n" + " self::REQUEST_URI_TOO_LARGE => 'Request-URI Too Large',\n" + " self::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',\n" " self::REQUESTED_RANGE_NOT_SATISFIABLE => 'Requested range not satisfiable',\n" - " self::EXPECTATION_FAILED => 'Expectation Failed',\n" - " self::MISDIRECTED_REQUEST => 'Misdirected Request',\n" - " self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity',\n" - " self::LOCKED => 'Locked',\n" - " self::FAILED_DEPENDENCY => 'Failed Dependency',\n" - " self::UNORDERED_COLLECTION => 'Unordered Collection',\n" - " self::UPGRADE_REQUIRED => 'Upgrade Required',\n" - " self::PRECONDITION_REQUIRED => 'Precondition Required',\n" - " self::TOO_MANY_REQUESTS => 'Too Many Requests',\n" + " self::EXPECTATION_FAILED => 'Expectation Failed',\n" + " self::MISDIRECTED_REQUEST => 'Misdirected Request',\n" + " self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity',\n" + " self::LOCKED => 'Locked',\n" + " self::FAILED_DEPENDENCY => 'Failed Dependency',\n" + " self::UNORDERED_COLLECTION => 'Unordered Collection',\n" + " self::UPGRADE_REQUIRED => 'Upgrade Required',\n" + " self::PRECONDITION_REQUIRED => 'Precondition Required',\n" + " self::TOO_MANY_REQUESTS => 'Too Many Requests',\n" " self::REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large',\n" - " self::UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons',\n" - " self::INTERNAL_SERVER_ERROR => 'Internal Server Error',\n" - " self::NOT_IMPLEMENTED => 'Not Implemented',\n" - " self::BAD_GATEWAY => 'Bad Gateway',\n" - " self::SERVICE_UNAVAILABLE => 'Service Unavailable',\n" - " self::GATEWAY_TIME_OUT => 'Gateway Time-out',\n" - " self::HTTP_VERSION_NOT_SUPPORTED => 'HTTP Version not supported',\n" - " self::VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates',\n" - " self::INSUFFICIENT_STORAGE => 'Insufficient Storage',\n" - " self::LOOP_DETECTED => 'Loop Detected',\n" - " self::NOT_EXTENDED => 'Not Extended',\n" + " self::UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons',\n" + " self::INTERNAL_SERVER_ERROR => 'Internal Server Error',\n" + " self::NOT_IMPLEMENTED => 'Not Implemented',\n" + " self::BAD_GATEWAY => 'Bad Gateway',\n" + " self::SERVICE_UNAVAILABLE => 'Service Unavailable',\n" + " self::GATEWAY_TIME_OUT => 'Gateway Time-out',\n" + " self::HTTP_VERSION_NOT_SUPPORTED => 'HTTP Version not supported',\n" + " self::VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates',\n" + " self::INSUFFICIENT_STORAGE => 'Insufficient Storage',\n" + " self::LOOP_DETECTED => 'Loop Detected',\n" + " self::NOT_EXTENDED => 'Not Extended',\n" " self::NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required',\n" " ];\n" "\n" @@ -3901,7 +3694,7 @@ static const char* swoole_library_source_core_curl_handler = "use Swoole\\Curl\\Exception as CurlException;\n" "use Swoole\\Http\\Status;\n" "\n" - "final class Handler\n" + "final class Handler implements \\Stringable\n" "{\n" " /**\n" " * @var Client\n" @@ -3909,37 +3702,37 @@ static const char* swoole_library_source_core_curl_handler = " private $client;\n" "\n" " private $info = [\n" - " 'url' => '',\n" - " 'content_type' => '',\n" - " 'http_code' => 0,\n" - " 'header_size' => 0,\n" - " 'request_size' => 0,\n" - " 'filetime' => -1,\n" - " 'ssl_verify_result' => 0,\n" - " 'redirect_count' => 0,\n" - " 'total_time' => 5.3E-5,\n" - " 'namelookup_time' => 0.0,\n" - " 'connect_time' => 0.0,\n" - " 'pretransfer_time' => 0.0,\n" - " 'size_upload' => 0.0,\n" - " 'size_download' => 0.0,\n" - " 'speed_download' => 0.0,\n" - " 'speed_upload' => 0.0,\n" + " 'url' => '',\n" + " 'content_type' => '',\n" + " 'http_code' => 0,\n" + " 'header_size' => 0,\n" + " 'request_size' => 0,\n" + " 'filetime' => -1,\n" + " 'ssl_verify_result' => 0,\n" + " 'redirect_count' => 0,\n" + " 'total_time' => 5.3E-5,\n" + " 'namelookup_time' => 0.0,\n" + " 'connect_time' => 0.0,\n" + " 'pretransfer_time' => 0.0,\n" + " 'size_upload' => 0.0,\n" + " 'size_download' => 0.0,\n" + " 'speed_download' => 0.0,\n" + " 'speed_upload' => 0.0,\n" " 'download_content_length' => -1.0,\n" - " 'upload_content_length' => -1.0,\n" - " 'starttransfer_time' => 0.0,\n" - " 'redirect_time' => 0.0,\n" - " 'redirect_url' => '',\n" - " 'primary_ip' => '',\n" - " 'certinfo' => [],\n" - " 'primary_port' => 0,\n" - " 'local_ip' => '',\n" - " 'local_port' => 0,\n" - " 'http_version' => 0,\n" - " 'protocol' => 0,\n" - " 'ssl_verifyresult' => 0,\n" - " 'scheme' => '',\n" - " 'private' => '',\n" + " 'upload_content_length' => -1.0,\n" + " 'starttransfer_time' => 0.0,\n" + " 'redirect_time' => 0.0,\n" + " 'redirect_url' => '',\n" + " 'primary_ip' => '',\n" + " 'certinfo' => [],\n" + " 'primary_port' => 0,\n" + " 'local_ip' => '',\n" + " 'local_port' => 0,\n" + " 'http_version' => 0,\n" + " 'protocol' => 0,\n" + " 'ssl_verifyresult' => 0,\n" + " 'scheme' => '',\n" + " 'private' => '',\n" " ];\n" "\n" " private $withHeaderOut = false;\n" @@ -4023,7 +3816,7 @@ static const char* swoole_library_source_core_curl_handler = " }\n" " }\n" "\n" - " public function __toString()\n" + " public function __toString(): string\n" " {\n" " $id = spl_object_id($this);\n" " return \"Object({$id}) of type (curl)\";\n" @@ -4073,7 +3866,7 @@ static const char* swoole_library_source_core_curl_handler = " if (!$this->isAvailable()) {\n" " return false;\n" " }\n" - " foreach ((new \\ReflectionClass(static::class))->getDefaultProperties() as $name => $value) {\n" + " foreach ((new \\ReflectionClass(self::class))->getDefaultProperties() as $name => $value) {\n" " $this->{$name} = $value;\n" " }\n" " }\n" @@ -4142,7 +3935,7 @@ static const char* swoole_library_source_core_curl_handler = " $this->setError(CURLE_URL_MALFORMAT, 'No URL set!');\n" " return false;\n" " }\n" - " if (strpos($url, '://') === false && $this->unix_socket_path === '') {\n" + " if (!str_contains($url, '://') && $this->unix_socket_path === '') {\n" " $url = 'http://' . $url;\n" " }\n" " if ($setInfo) {\n" @@ -4213,7 +4006,7 @@ static const char* swoole_library_source_core_curl_handler = " private function setError($code, $msg = ''): void\n" " {\n" " $this->errCode = $code;\n" - " $this->errMsg = $msg ?: curl_strerror($code);\n" + " $this->errMsg = $msg ?: curl_strerror($code);\n" " }\n" "\n" " private function hasHeader(string $headerName): bool\n" @@ -4230,7 +4023,7 @@ static const char* swoole_library_source_core_curl_handler = " }\n" "\n" " if ($value !== '') {\n" - " $this->headers[$headerName] = $value;\n" + " $this->headers[$headerName] = $value;\n" " $this->headerMap[$lowerCaseHeaderName] = $headerName;\n" " } else {\n" " // remove empty headers (keep same with raw cURL)\n" @@ -4239,10 +4032,9 @@ static const char* swoole_library_source_core_curl_handler = " }\n" "\n" " /**\n" - " * @param mixed $value\n" " * @throws Swoole\\Curl\\Exception\n" " */\n" - " private function setOption(int $opt, $value): bool\n" + " private function setOption(int $opt, mixed $value): bool\n" " {\n" " switch ($opt) {\n" " // case CURLOPT_STDERR:\n" @@ -4270,7 +4062,7 @@ static const char* swoole_library_source_core_curl_handler = " break;\n" " case CURLOPT_RETURNTRANSFER:\n" " $this->returnTransfer = $value;\n" - " $this->transfer = '';\n" + " $this->transfer = '';\n" " break;\n" " case CURLOPT_ENCODING:\n" " if (empty($value)) {\n" @@ -4292,9 +4084,7 @@ static const char* swoole_library_source_core_curl_handler = " break;\n" " case CURLOPT_PROXYTYPE:\n" " if ($value !== CURLPROXY_HTTP and $value !== CURLPROXY_SOCKS5) {\n" - " throw new Swoole\\Curl\\Exception(\n" - " 'swoole_curl_setopt(): Only support following CURLOPT_PROXYTYPE values: CURLPROXY_HTTP, CURLPROXY_SOCKS5'\n" - " );\n" + " throw new Swoole\\Curl\\Exception('swoole_curl_setopt(): Only support following CURLOPT_PROXYTYPE values: CURLPROXY_HTTP, CURLPROXY_SOCKS5');\n" " }\n" " $this->proxyType = $value;\n" " break;\n" @@ -4311,7 +4101,7 @@ static const char* swoole_library_source_core_curl_handler = " $this->proxyPassword = $value;\n" " break;\n" " case CURLOPT_PROXYUSERPWD:\n" - " $usernamePassword = explode(':', $value);\n" + " $usernamePassword = explode(':', $value);\n" " $this->proxyUsername = urldecode($usernamePassword[0]);\n" " $this->proxyPassword = urldecode($usernamePassword[1] ?? null);\n" " break;\n" @@ -4338,9 +4128,9 @@ static const char* swoole_library_source_core_curl_handler = " $resolve = substr($resolve, 1);\n" " }\n" " $tmpResolve = explode(':', $resolve, 3);\n" - " $host = $tmpResolve[0] ?? '';\n" - " $port = $tmpResolve[1] ?? 0;\n" - " $ip = $tmpResolve[2] ?? '';\n" + " $host = $tmpResolve[0] ?? '';\n" + " $port = $tmpResolve[1] ?? 0;\n" + " $ip = $tmpResolve[2] ?? '';\n" " if ($flag === '-') {\n" " unset($this->resolve[$host][$port]);\n" " } else {\n" @@ -4351,9 +4141,7 @@ static const char* swoole_library_source_core_curl_handler = " break;\n" " case CURLOPT_IPRESOLVE:\n" " if ($value !== CURL_IPRESOLVE_WHATEVER and $value !== CURL_IPRESOLVE_V4) {\n" - " throw new Swoole\\Curl\\Exception(\n" - " 'swoole_curl_setopt(): Only support following CURLOPT_IPRESOLVE values: CURL_IPRESOLVE_WHATEVER, CURL_IPRESOLVE_V4'\n" - " );\n" + " throw new Swoole\\Curl\\Exception('swoole_curl_setopt(): Only support following CURLOPT_IPRESOLVE values: CURL_IPRESOLVE_WHATEVER, CURL_IPRESOLVE_V4');\n" " }\n" " break;\n" " case CURLOPT_TCP_NODELAY:\n" @@ -4442,8 +4230,8 @@ static const char* swoole_library_source_core_curl_handler = " return false;\n" " }\n" " foreach ($value as $header) {\n" - " $header = explode(':', $header, 2);\n" - " $headerName = $header[0];\n" + " $header = explode(':', $header, 2);\n" + " $headerName = $header[0];\n" " $headerValue = trim($header[1] ?? '');\n" " $this->setHeader($headerName, $headerValue);\n" " }\n" @@ -4571,8 +4359,8 @@ static const char* swoole_library_source_core_curl_handler = " private function execute()\n" " {\n" " $this->info['redirect_count'] = $this->info['starttransfer_time'] = 0;\n" - " $this->info['redirect_url'] = '';\n" - " $timeBegin = microtime(true);\n" + " $this->info['redirect_url'] = '';\n" + " $timeBegin = microtime(true);\n" " /*\n" " * Socket\n" " */\n" @@ -4589,12 +4377,12 @@ static const char* swoole_library_source_core_curl_handler = " * Http Proxy\n" " */\n" " if ($this->proxy) {\n" - " $parse = parse_url($this->proxy);\n" - " $proxy = $parse['host'] ?? $parse['path'];\n" - " $proxyPort = $parse['port'] ?? $this->proxyPort;\n" + " $parse = parse_url($this->proxy);\n" + " $proxy = $parse['host'] ?? $parse['path'];\n" + " $proxyPort = $parse['port'] ?? $this->proxyPort;\n" " $proxyUsername = $parse['user'] ?? $this->proxyUsername;\n" " $proxyPassword = $parse['pass'] ?? $this->proxyPassword;\n" - " $proxyType = $parse['scheme'] ?? $this->proxyType;\n" + " $proxyType = $parse['scheme'] ?? $this->proxyType;\n" " if (is_string($proxyType)) {\n" " if ($proxyType === 'socks5') {\n" " $proxyType = CURLPROXY_SOCKS5;\n" @@ -4611,26 +4399,21 @@ static const char* swoole_library_source_core_curl_handler = " }\n" " $this->proxy = $proxy = $ip;\n" " }\n" - " switch ($proxyType) {\n" - " case CURLPROXY_HTTP:\n" - " $proxyOptions = [\n" - " 'http_proxy_host' => $proxy,\n" - " 'http_proxy_port' => $proxyPort,\n" - " 'http_proxy_username' => $proxyUsername,\n" - " 'http_proxy_password' => $proxyPassword,\n" - " ];\n" - " break;\n" - " case CURLPROXY_SOCKS5:\n" - " $proxyOptions = [\n" - " 'socks5_host' => $proxy,\n" - " 'socks5_port' => $proxyPort,\n" - " 'socks5_username' => $proxyUsername,\n" - " 'socks5_password' => $proxyPassword,\n" - " ];\n" - " break;\n" - " default:\n" - " throw new CurlException(\"Unexpected proxy type [{$proxyType}]\");\n" - " }\n" + " $proxyOptions = match ($proxyType) {\n" + " CURLPROXY_HTTP => [\n" + " 'http_proxy_host' => $proxy,\n" + " 'http_proxy_port' => $proxyPort,\n" + " 'http_proxy_username' => $proxyUsername,\n" + " 'http_proxy_password' => $proxyPassword,\n" + " ],\n" + " CURLPROXY_SOCKS5 => [\n" + " 'socks5_host' => $proxy,\n" + " 'socks5_port' => $proxyPort,\n" + " 'socks5_username' => $proxyUsername,\n" + " 'socks5_password' => $proxyPassword,\n" + " ],\n" + " default => throw new CurlException(\"Unexpected proxy type [{$proxyType}]\"),\n" + " };\n" " }\n" " /*\n" " * Client Options\n" @@ -4664,7 +4447,7 @@ static const char* swoole_library_source_core_curl_handler = " }\n" " $client->setData($data);\n" " // Notice: although we reset it, raw cURL never do this\n" - " $this->infile = null;\n" + " $this->infile = null;\n" " $this->infileSize = PHP_INT_MAX;\n" " } else {\n" " // POST data\n" @@ -4707,11 +4490,11 @@ static const char* swoole_library_source_core_curl_handler = " }\n" " if ($client->statusCode >= 300 and $client->statusCode < 400 and isset($client->headers['location'])) {\n" " $redirectParsedUrl = $this->getRedirectUrl($client->headers['location']);\n" - " $redirectUrl = static::unparseUrl($redirectParsedUrl);\n" + " $redirectUrl = self::unparseUrl($redirectParsedUrl);\n" " if ($this->followLocation and ($this->maxRedirects === null or $this->info['redirect_count'] < $this->maxRedirects)) {\n" " if ($this->info['redirect_count'] === 0) {\n" " $this->info['starttransfer_time'] = microtime(true) - $timeBegin;\n" - " $redirectBeginTime = microtime(true);\n" + " $redirectBeginTime = microtime(true);\n" " }\n" " // force GET\n" " if (in_array($client->statusCode, [Status::MOVED_PERMANENTLY, Status::FOUND, Status::SEE_OTHER])) {\n" @@ -4734,10 +4517,10 @@ static const char* swoole_library_source_core_curl_handler = " break;\n" " }\n" " }\n" - " $this->info['total_time'] = microtime(true) - $timeBegin;\n" - " $this->info['http_code'] = $client->statusCode;\n" - " $this->info['content_type'] = $client->headers['content-type'] ?? '';\n" - " $this->info['size_download'] = $this->info['download_content_length'] = strlen($client->body);\n" + " $this->info['total_time'] = microtime(true) - $timeBegin;\n" + " $this->info['http_code'] = $client->statusCode;\n" + " $this->info['content_type'] = $client->headers['content-type'] ?? '';\n" + " $this->info['size_download'] = $this->info['download_content_length'] = strlen($client->body);\n" " $this->info['speed_download'] = 1 / $this->info['total_time'] * $this->info['size_download'];\n" " if (isset($redirectBeginTime)) {\n" " $this->info['redirect_time'] = microtime(true) - $redirectBeginTime;\n" @@ -4748,7 +4531,7 @@ static const char* swoole_library_source_core_curl_handler = " }\n" "\n" " if ($this->unix_socket_path) {\n" - " $this->info['primary_ip'] = $this->unix_socket_path;\n" + " $this->info['primary_ip'] = $this->unix_socket_path;\n" " $this->info['primary_port'] = $this->urlInfo['port'];\n" " }\n" "\n" @@ -4790,7 +4573,7 @@ static const char* swoole_library_source_core_curl_handler = " }\n" "\n" " if ($this->withHeaderOut) {\n" - " $headerOutContent = $client->getHeaderOut();\n" + " $headerOutContent = $client->getHeaderOut();\n" " $this->info['request_header'] = $headerOutContent ? $headerOutContent . \"\\r\\n\\r\\n\" : '';\n" " }\n" " if ($this->withFileTime) {\n" @@ -4840,14 +4623,14 @@ static const char* swoole_library_source_core_curl_handler = "\n" " private static function unparseUrl(array $parsedUrl): string\n" " {\n" - " $scheme = ($parsedUrl['scheme'] ?? 'http') . '://';\n" - " $host = $parsedUrl['host'] ?? '';\n" - " $port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : '';\n" - " $user = $parsedUrl['user'] ?? '';\n" - " $pass = isset($parsedUrl['pass']) ? ':' . $parsedUrl['pass'] : '';\n" - " $pass = ($user or $pass) ? \"{$pass}@\" : '';\n" - " $path = $parsedUrl['path'] ?? '';\n" - " $query = (isset($parsedUrl['query']) and $parsedUrl['query'] !== '') ? '?' . $parsedUrl['query'] : '';\n" + " $scheme = ($parsedUrl['scheme'] ?? 'http') . '://';\n" + " $host = $parsedUrl['host'] ?? '';\n" + " $port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : '';\n" + " $user = $parsedUrl['user'] ?? '';\n" + " $pass = isset($parsedUrl['pass']) ? ':' . $parsedUrl['pass'] : '';\n" + " $pass = ($user or $pass) ? \"{$pass}@\" : '';\n" + " $path = $parsedUrl['path'] ?? '';\n" + " $query = (isset($parsedUrl['query']) and $parsedUrl['query'] !== '') ? '?' . $parsedUrl['query'] : '';\n" " $fragment = isset($parsedUrl['fragment']) ? '#' . $parsedUrl['fragment'] : '';\n" " return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;\n" " }\n" @@ -4861,7 +4644,7 @@ static const char* swoole_library_source_core_curl_handler = " if (!isset($location[0])) {\n" " return [];\n" " }\n" - " $redirectUri = $this->urlInfo;\n" + " $redirectUri = $this->urlInfo;\n" " $redirectUri['query'] = '';\n" " if ($location[0] === '/') {\n" " $redirectUri['path'] = $location;\n" @@ -4870,7 +4653,7 @@ static const char* swoole_library_source_core_curl_handler = " if ($path === '.') {\n" " $path = '/';\n" " }\n" - " if (isset($location[1]) and substr($location, 0, 2) === './') {\n" + " if (isset($location[1]) and str_starts_with($location, './')) {\n" " $location = substr($location, 2);\n" " }\n" " $redirectUri['path'] = $path . $location;\n" @@ -5002,63 +4785,47 @@ static const char* swoole_library_source_core_fast_cgi_record = "/**\n" " * FastCGI record.\n" " */\n" - "class Record\n" + "class Record implements \\Stringable\n" "{\n" " /**\n" " * Identifies the FastCGI protocol version.\n" - " *\n" - " * @var int\n" " */\n" - " protected $version = FastCGI::VERSION_1;\n" + " protected int $version = FastCGI::VERSION_1;\n" "\n" " /**\n" " * Identifies the FastCGI record type, i.e. the general function that the record performs.\n" - " *\n" - " * @var int\n" " */\n" - " protected $type = FastCGI::UNKNOWN_TYPE;\n" + " protected int $type = FastCGI::UNKNOWN_TYPE;\n" "\n" " /**\n" " * Identifies the FastCGI request to which the record belongs.\n" - " *\n" - " * @var int\n" " */\n" - " protected $requestId = FastCGI::DEFAULT_REQUEST_ID;\n" + " protected int $requestId = FastCGI::DEFAULT_REQUEST_ID;\n" "\n" " /**\n" " * Reserved byte for future proposes\n" - " *\n" - " * @var int\n" " */\n" - " protected $reserved = 0;\n" + " protected int $reserved = 0;\n" "\n" " /**\n" " * The number of bytes in the contentData component of the record.\n" - " *\n" - " * @var int\n" " */\n" - " private $contentLength = 0;\n" + " private int $contentLength = 0;\n" "\n" " /**\n" " * The number of bytes in the paddingData component of the record.\n" - " *\n" - " * @var int\n" " */\n" - " private $paddingLength = 0;\n" + " private int $paddingLength = 0;\n" "\n" " /**\n" " * Binary data, between 0 and 65535 bytes of data, interpreted according to the record type.\n" - " *\n" - " * @var string\n" " */\n" - " private $contentData = '';\n" + " private string $contentData = '';\n" "\n" " /**\n" " * Padding data, between 0 and 255 bytes of data, which are ignored.\n" - " *\n" - " * @var string\n" " */\n" - " private $paddingData = '';\n" + " private string $paddingData = '';\n" "\n" " /**\n" " * Returns the binary message representation of record\n" @@ -5085,12 +4852,10 @@ static const char* swoole_library_source_core_fast_cgi_record = " * Unpacks the message from the binary data buffer\n" " *\n" " * @param string $data Binary buffer with raw data\n" - " *\n" - " * @return static\n" " */\n" - " final public static function unpack(string $data): self\n" + " final public static function unpack(string $data): static\n" " {\n" - " $self = new static();\n" + " $self = new static(); // @phpstan-ignore new.static\n" " [\n" " $self->version,\n" " $self->type,\n" @@ -5102,7 +4867,7 @@ static const char* swoole_library_source_core_fast_cgi_record = "\n" " $payload = substr($data, FastCGI::HEADER_LEN);\n" " self::unpackPayload($self, $payload);\n" - " if (get_called_class() !== __CLASS__ && $self->contentLength > 0) {\n" + " if (static::class !== self::class && $self->contentLength > 0) {\n" " static::unpackPayload($self, $payload);\n" " }\n" "\n" @@ -5119,11 +4884,11 @@ static const char* swoole_library_source_core_fast_cgi_record = " $this->contentLength = strlen($data);\n" " if ($this->contentLength > FastCGI::MAX_CONTENT_LENGTH) {\n" " $this->contentLength = FastCGI::MAX_CONTENT_LENGTH;\n" - " $this->contentData = substr($data, 0, FastCGI::MAX_CONTENT_LENGTH);\n" + " $this->contentData = substr($data, 0, FastCGI::MAX_CONTENT_LENGTH);\n" " } else {\n" " $this->contentData = $data;\n" " }\n" - " $extraLength = $this->contentLength % 8;\n" + " $extraLength = $this->contentLength % 8;\n" " $this->paddingLength = $extraLength ? (8 - $extraLength) : 0;\n" " return $this;\n" " }\n" @@ -5251,7 +5016,7 @@ static const char* swoole_library_source_core_fast_cgi_record_params = " */\n" " public function __construct(array $values = [])\n" " {\n" - " $this->type = FastCGI::PARAMS;\n" + " $this->type = FastCGI::PARAMS;\n" " $this->values = $values;\n" " $this->setContentData($this->packPayload());\n" " }\n" @@ -5273,18 +5038,18 @@ static const char* swoole_library_source_core_fast_cgi_record_params = " $currentOffset = 0;\n" " do {\n" " [$nameLengthHigh] = array_values(unpack('CnameLengthHigh', $data));\n" - " $isLongName = ($nameLengthHigh >> 7 == 1);\n" - " $valueOffset = $isLongName ? 4 : 1;\n" + " $isLongName = ($nameLengthHigh >> 7 == 1);\n" + " $valueOffset = $isLongName ? 4 : 1;\n" "\n" " [$valueLengthHigh] = array_values(unpack('CvalueLengthHigh', substr($data, $valueOffset)));\n" - " $isLongValue = ($valueLengthHigh >> 7 == 1);\n" - " $dataOffset = $valueOffset + ($isLongValue ? 4 : 1);\n" + " $isLongValue = ($valueLengthHigh >> 7 == 1);\n" + " $dataOffset = $valueOffset + ($isLongValue ? 4 : 1);\n" "\n" " $formatParts = [\n" " $isLongName ? 'NnameLength' : 'CnameLength',\n" " $isLongValue ? 'NvalueLength' : 'CvalueLength',\n" " ];\n" - " $format = join('/', $formatParts);\n" + " $format = join('/', $formatParts);\n" " [$nameLength, $valueLength] = array_values(unpack($format, $data));\n" "\n" " // Clear top bit for long record\n" @@ -5301,7 +5066,7 @@ static const char* swoole_library_source_core_fast_cgi_record_params = " $self->values[$nameData] = $valueData;\n" "\n" " $keyValueLength = $dataOffset + $nameLength + $valueLength;\n" - " $data = substr($data, $keyValueLength);\n" + " $data = substr($data, $keyValueLength);\n" " $currentOffset += $keyValueLength;\n" " } while ($currentOffset < $self->getContentLength());\n" " }\n" @@ -5314,9 +5079,9 @@ static const char* swoole_library_source_core_fast_cgi_record_params = " if ($valueData === null) {\n" " continue;\n" " }\n" - " $nameLength = strlen($nameData);\n" + " $nameLength = strlen($nameData);\n" " $valueLength = strlen((string) $valueData);\n" - " $isLongName = $nameLength > 127;\n" + " $isLongName = $nameLength > 127;\n" " $isLongValue = $valueLength > 127;\n" " $formatParts = [\n" " $isLongName ? 'N' : 'C',\n" @@ -5422,9 +5187,9 @@ static const char* swoole_library_source_core_fast_cgi_record_begin_request = "\n" " public function __construct(int $role = FastCGI::UNKNOWN_ROLE, int $flags = 0, string $reserved = '')\n" " {\n" - " $this->type = FastCGI::BEGIN_REQUEST;\n" - " $this->role = $role;\n" - " $this->flags = $flags;\n" + " $this->type = FastCGI::BEGIN_REQUEST;\n" + " $this->role = $role;\n" + " $this->flags = $flags;\n" " $this->reserved1 = $reserved;\n" " $this->setContentData($this->packPayload());\n" " }\n" @@ -5573,10 +5338,10 @@ static const char* swoole_library_source_core_fast_cgi_record_end_request = " int $appStatus = 0,\n" " string $reserved = ''\n" " ) {\n" - " $this->type = FastCGI::END_REQUEST;\n" + " $this->type = FastCGI::END_REQUEST;\n" " $this->protocolStatus = $protocolStatus;\n" - " $this->appStatus = $appStatus;\n" - " $this->reserved1 = $reserved;\n" + " $this->appStatus = $appStatus;\n" + " $this->reserved1 = $reserved;\n" " $this->setContentData($this->packPayload());\n" " }\n" "\n" @@ -5867,8 +5632,8 @@ static const char* swoole_library_source_core_fast_cgi_record_unknown_type = "\n" " public function __construct(int $type = 0, string $reserved = '')\n" " {\n" - " $this->type = FastCGI::UNKNOWN_TYPE;\n" - " $this->type1 = $type;\n" + " $this->type = FastCGI::UNKNOWN_TYPE;\n" + " $this->type1 = $type;\n" " $this->reserved1 = $reserved;\n" " $this->setContentData($this->packPayload());\n" " }\n" @@ -5928,17 +5693,17 @@ static const char* swoole_library_source_core_fast_cgi_frame_parser = " * @var array\n" " */\n" " protected static $classMapping = [\n" - " FastCGI::BEGIN_REQUEST => FastCGI\\Record\\BeginRequest::class,\n" - " FastCGI::ABORT_REQUEST => FastCGI\\Record\\AbortRequest::class,\n" - " FastCGI::END_REQUEST => FastCGI\\Record\\EndRequest::class,\n" - " FastCGI::PARAMS => FastCGI\\Record\\Params::class,\n" - " FastCGI::STDIN => FastCGI\\Record\\Stdin::class,\n" - " FastCGI::STDOUT => FastCGI\\Record\\Stdout::class,\n" - " FastCGI::STDERR => FastCGI\\Record\\Stderr::class,\n" - " FastCGI::DATA => FastCGI\\Record\\Data::class,\n" - " FastCGI::GET_VALUES => FastCGI\\Record\\GetValues::class,\n" + " FastCGI::BEGIN_REQUEST => FastCGI\\Record\\BeginRequest::class,\n" + " FastCGI::ABORT_REQUEST => FastCGI\\Record\\AbortRequest::class,\n" + " FastCGI::END_REQUEST => FastCGI\\Record\\EndRequest::class,\n" + " FastCGI::PARAMS => FastCGI\\Record\\Params::class,\n" + " FastCGI::STDIN => FastCGI\\Record\\Stdin::class,\n" + " FastCGI::STDOUT => FastCGI\\Record\\Stdout::class,\n" + " FastCGI::STDERR => FastCGI\\Record\\Stderr::class,\n" + " FastCGI::DATA => FastCGI\\Record\\Data::class,\n" + " FastCGI::GET_VALUES => FastCGI\\Record\\GetValues::class,\n" " FastCGI::GET_VALUES_RESULT => FastCGI\\Record\\GetValuesResult::class,\n" - " FastCGI::UNKNOWN_TYPE => FastCGI\\Record\\UnknownType::class,\n" + " FastCGI::UNKNOWN_TYPE => FastCGI\\Record\\UnknownType::class,\n" " ];\n" "\n" " /**\n" @@ -5975,14 +5740,14 @@ static const char* swoole_library_source_core_fast_cgi_frame_parser = " throw new \\RuntimeException('Not enough data in the buffer to parse');\n" " }\n" " $recordHeader = unpack(FastCGI::HEADER_FORMAT, $buffer);\n" - " $recordType = $recordHeader['type'];\n" + " $recordType = $recordHeader['type'];\n" " if (!isset(self::$classMapping[$recordType])) {\n" " throw new \\DomainException(\"Invalid FastCGI record type {$recordType} received\");\n" " }\n" "\n" " /** @var Record $className */\n" " $className = self::$classMapping[$recordType];\n" - " $record = $className::unpack($buffer);\n" + " $record = $className::unpack($buffer);\n" "\n" " $offset = FastCGI::HEADER_LEN + $record->getContentLength() + $record->getPaddingLength();\n" " $buffer = substr($buffer, $offset);\n" @@ -6007,14 +5772,11 @@ static const char* swoole_library_source_core_fast_cgi_message = "\n" "class Message\n" "{\n" - " /** @var array */\n" - " protected $params = [];\n" + " protected array $params = [];\n" "\n" - " /** @var string */\n" - " protected $body = '';\n" + " protected string $body = '';\n" "\n" - " /** @var string */\n" - " protected $error = '';\n" + " protected string $error = '';\n" "\n" " public function getParam(string $name): ?string\n" " {\n" @@ -6092,16 +5854,16 @@ static const char* swoole_library_source_core_fast_cgi_request = "use Swoole\\FastCGI\\Record\\Params;\n" "use Swoole\\FastCGI\\Record\\Stdin;\n" "\n" - "class Request extends Message\n" + "class Request extends Message implements \\Stringable\n" "{\n" - " protected $keepConn = false;\n" + " protected bool $keepConn = false;\n" "\n" " public function __toString(): string\n" " {\n" - " $body = $this->getBody();\n" + " $body = $this->getBody();\n" " $beginRequestFrame = new BeginRequest(FastCGI::RESPONDER, $this->keepConn ? FastCGI::KEEP_CONN : 0);\n" - " $paramsFrame = new Params($this->getParams());\n" - " $paramsEofFrame = new Params();\n" + " $paramsFrame = new Params($this->getParams());\n" + " $paramsEofFrame = new Params();\n" " if (empty($body)) {\n" " $message = \"{$beginRequestFrame}{$paramsFrame}{$paramsEofFrame}}\";\n" " } else {\n" @@ -6115,8 +5877,8 @@ static const char* swoole_library_source_core_fast_cgi_request = " $body = substr($body, $stdinLength);\n" " }\n" " $stdinList[] = new Stdin();\n" - " $stdin = implode($stdinList);\n" - " $message = \"{$beginRequestFrame}{$paramsFrame}{$paramsEofFrame}{$stdin}}\";\n" + " $stdin = implode('', $stdinList);\n" + " $message = \"{$beginRequestFrame}{$paramsFrame}{$paramsEofFrame}{$stdin}}\";\n" " }\n" " return $message;\n" " }\n" @@ -6158,7 +5920,7 @@ static const char* swoole_library_source_core_fast_cgi_response = " if (!static::verify($records)) {\n" " throw new \\InvalidArgumentException('Bad records');\n" " }\n" - " $body = '';\n" + " $body = '';\n" " $error = '';\n" " foreach ($records as $record) {\n" " if ($record instanceof Stdout) {\n" @@ -6196,26 +5958,26 @@ static const char* swoole_library_source_core_fast_cgi_http_request = "\n" "class HttpRequest extends Request\n" "{\n" - " protected $params = [\n" - " 'REQUEST_SCHEME' => 'http',\n" - " 'REQUEST_METHOD' => 'GET',\n" - " 'DOCUMENT_ROOT' => '',\n" - " 'SCRIPT_FILENAME' => '',\n" - " 'SCRIPT_NAME' => '',\n" - " 'DOCUMENT_URI' => '/',\n" - " 'REQUEST_URI' => '/',\n" - " 'QUERY_STRING' => '',\n" - " 'CONTENT_TYPE' => 'text/plain',\n" - " 'CONTENT_LENGTH' => '0',\n" + " protected array $params = [\n" + " 'REQUEST_SCHEME' => 'http',\n" + " 'REQUEST_METHOD' => 'GET',\n" + " 'DOCUMENT_ROOT' => '',\n" + " 'SCRIPT_FILENAME' => '',\n" + " 'SCRIPT_NAME' => '',\n" + " 'DOCUMENT_URI' => '/',\n" + " 'REQUEST_URI' => '/',\n" + " 'QUERY_STRING' => '',\n" + " 'CONTENT_TYPE' => 'text/plain',\n" + " 'CONTENT_LENGTH' => '0',\n" " 'GATEWAY_INTERFACE' => 'CGI/1.1',\n" - " 'SERVER_PROTOCOL' => 'HTTP/1.1',\n" - " 'SERVER_SOFTWARE' => 'swoole/' . SWOOLE_VERSION,\n" - " 'REMOTE_ADDR' => 'unknown',\n" - " 'REMOTE_PORT' => '0',\n" - " 'SERVER_ADDR' => 'unknown',\n" - " 'SERVER_PORT' => '0',\n" - " 'SERVER_NAME' => 'Swoole',\n" - " 'REDIRECT_STATUS' => '200',\n" + " 'SERVER_PROTOCOL' => 'HTTP/1.1',\n" + " 'SERVER_SOFTWARE' => 'swoole/' . SWOOLE_VERSION,\n" + " 'REMOTE_ADDR' => 'unknown',\n" + " 'REMOTE_PORT' => '0',\n" + " 'SERVER_ADDR' => 'unknown',\n" + " 'SERVER_PORT' => '0',\n" + " 'SERVER_NAME' => 'Swoole',\n" + " 'REDIRECT_STATUS' => '200',\n" " ];\n" "\n" " public function getScheme(): ?string\n" @@ -6303,7 +6065,8 @@ static const char* swoole_library_source_core_fast_cgi_http_request = " $info = parse_url($uri);\n" " return $this->withRequestUri($uri)\n" " ->withDocumentUri($info['path'] ?? '')\n" - " ->withQueryString($info['query'] ?? '');\n" + " ->withQueryString($info['query'] ?? '')\n" + " ;\n" " }\n" "\n" " public function getDocumentUri(): ?string\n" @@ -6567,7 +6330,7 @@ static const char* swoole_library_source_core_fast_cgi_http_request = " {\n" " $headers = [];\n" " foreach ($this->params as $name => $value) {\n" - " if (strpos($name, 'HTTP_') === 0) {\n" + " if (str_starts_with($name, 'HTTP_')) {\n" " $headers[static::convertParamNameToHeaderName($name)] = $value;\n" " }\n" " }\n" @@ -6582,8 +6345,7 @@ static const char* swoole_library_source_core_fast_cgi_http_request = " return $this;\n" " }\n" "\n" - " /** @return $this */\n" - " public function withBody($body): Message\n" + " public function withBody($body): self\n" " {\n" " if (is_array($body)) {\n" " $body = http_build_query($body);\n" @@ -6650,17 +6412,17 @@ static const char* swoole_library_source_core_fast_cgi_http_response = " return;\n" " }\n" " $headers = explode(\"\\r\\n\", $array[0]);\n" - " $body = $array[1];\n" + " $body = $array[1];\n" " foreach ($headers as $header) {\n" " $array = explode(':', $header, 2); // An array that contains the name and the value of an HTTP header.\n" " if (count($array) != 2) {\n" " continue; // Invalid HTTP header? Ignore it!\n" " }\n" - " $name = trim($array[0]);\n" + " $name = trim($array[0]);\n" " $value = trim($array[1]);\n" " if (strcasecmp($name, 'Status') === 0) {\n" - " $array = explode(' ', $value, 2); // An array that contains the status code (and the reason phrase).\n" - " $statusCode = $array[0];\n" + " $array = explode(' ', $value, 2); // An array that contains the status code (and the reason phrase).\n" + " $statusCode = $array[0];\n" " $reasonPhrase = $array[1] ?? null;\n" " } elseif (strcasecmp($name, 'Set-Cookie') === 0) {\n" " $this->withSetCookieHeaderLine($value);\n" @@ -6668,7 +6430,7 @@ static const char* swoole_library_source_core_fast_cgi_http_response = " $this->withHeader($name, $value);\n" " }\n" " }\n" - " $statusCode = (int) ($statusCode ?? Status::OK);\n" + " $statusCode = (int) ($statusCode ?? Status::OK);\n" " $reasonPhrase = (string) ($reasonPhrase ?? Status::getReasonPhrase($statusCode));\n" " $this->withStatusCode($statusCode)->withReasonPhrase($reasonPhrase);\n" " $this->withBody($body);\n" @@ -6709,7 +6471,7 @@ static const char* swoole_library_source_core_fast_cgi_http_response = "\n" " public function withHeader(string $name, string $value): self\n" " {\n" - " $this->headers[$name] = $value;\n" + " $this->headers[$name] = $value;\n" " $this->headersMap[strtolower($name)] = $name;\n" " return $this;\n" " }\n" @@ -6759,47 +6521,42 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_client = "\n" "class Client\n" "{\n" - " /** @var int */\n" - " protected $af;\n" + " protected int $af;\n" "\n" - " /** @var string */\n" - " protected $host;\n" + " protected string $host;\n" "\n" - " /** @var int */\n" - " protected $port;\n" + " protected int $port;\n" "\n" - " /** @var bool */\n" - " protected $ssl;\n" + " protected bool $ssl;\n" "\n" - " /** @var Socket */\n" - " protected $socket;\n" + " protected ?Socket $socket;\n" "\n" " public function __construct(string $host, int $port = 0, bool $ssl = false)\n" " {\n" " if (stripos($host, 'unix:/') === 0) {\n" " $this->af = AF_UNIX;\n" - " $host = '/' . ltrim(substr($host, strlen('unix:/')), '/');\n" - " $port = 0;\n" - " } elseif (strpos($host, ':') !== false) {\n" + " $host = '/' . ltrim(substr($host, strlen('unix:/')), '/');\n" + " $port = 0;\n" + " } elseif (str_contains($host, ':')) {\n" " $this->af = AF_INET6;\n" " } else {\n" " $this->af = AF_INET;\n" " }\n" " $this->host = $host;\n" " $this->port = $port;\n" - " $this->ssl = $ssl;\n" + " $this->ssl = $ssl;\n" " }\n" "\n" " /**\n" - " * @throws Exception\n" " * @return HttpResponse|Response\n" + " * @throws Exception\n" " */\n" " public function execute(Request $request, float $timeout = -1): Response\n" " {\n" - " if (!$this->socket) {\n" + " if (!isset($this->socket)) {\n" " $this->socket = $socket = new Socket($this->af, SOCK_STREAM, IPPROTO_IP);\n" " $socket->setProtocol([\n" - " 'open_ssl' => $this->ssl,\n" + " 'open_ssl' => $this->ssl,\n" " 'open_fastcgi_protocol' => true,\n" " ]);\n" " if (!$socket->connect($this->host, $this->port, $timeout)) {\n" @@ -6814,33 +6571,17 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_client = " }\n" " $records = [];\n" " while (true) {\n" - " if (SWOOLE_VERSION_ID < 40500) {\n" - " $recvData = '';\n" - " while (true) {\n" - " $tmp = $socket->recv(8192, $timeout);\n" - " if (!$tmp) {\n" - " if ($tmp === '') {\n" - " $this->ioException(SOCKET_ECONNRESET);\n" - " }\n" - " $this->ioException();\n" - " }\n" - " $recvData .= $tmp;\n" - " if (FrameParser::hasFrame($recvData)) {\n" - " break;\n" - " }\n" - " }\n" - " } else {\n" - " $recvData = $socket->recvPacket($timeout);\n" - " if (!$recvData) {\n" - " if ($recvData === '') {\n" - " $this->ioException(SOCKET_ECONNRESET);\n" - " }\n" - " $this->ioException();\n" - " }\n" - " if (!FrameParser::hasFrame($recvData)) {\n" - " $this->ioException(SOCKET_EPROTO);\n" + " $recvData = $socket->recvPacket($timeout);\n" + " if (!$recvData) {\n" + " if ($recvData === '') {\n" + " $this->ioException(SOCKET_ECONNRESET);\n" " }\n" + " $this->ioException();\n" + " }\n" + " if (!FrameParser::hasFrame($recvData)) {\n" + " $this->ioException(SOCKET_EPROTO);\n" " }\n" + "\n" " do {\n" " $records[] = $record = FrameParser::parseFrame($recvData);\n" " } while (strlen($recvData) !== 0);\n" @@ -6849,21 +6590,20 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_client = " $this->socket->close();\n" " $this->socket = null;\n" " }\n" - " switch (true) {\n" - " case $request instanceof HttpRequest:\n" - " return new HttpResponse($records);\n" - " default:\n" - " return new Response($records);\n" - " }\n" + " return match (true) {\n" + " $request instanceof HttpRequest => new HttpResponse($records),\n" + " default => new Response($records),\n" + " };\n" " }\n" " }\n" - " /* never here */\n" - " exit(1);\n" + "\n" + " // Code execution should never reach here. However, we still put an exit() statement here for safe purpose.\n" + " exit(1); // @phpstan-ignore deadCode.unreachable\n" " }\n" "\n" " public static function parseUrl(string $url): array\n" " {\n" - " $url = parse_url($url);\n" + " $url = parse_url($url);\n" " $host = $url['host'] ?? '';\n" " $port = $url['port'] ?? 0;\n" " if (empty($host)) {\n" @@ -6878,15 +6618,15 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_client = "\n" " public static function call(string $url, string $path, $data = '', float $timeout = -1): string\n" " {\n" - " $client = new Client(...static::parseUrl($url));\n" - " $pathInfo = parse_url($path);\n" - " $path = $pathInfo['path'] ?? '';\n" - " $root = dirname($path);\n" - " $scriptName = '/' . basename($path);\n" + " $client = new Client(...static::parseUrl($url));\n" + " $pathInfo = parse_url($path);\n" + " $path = $pathInfo['path'] ?? '';\n" + " $root = dirname($path);\n" + " $scriptName = '/' . basename($path);\n" " $documentUri = $scriptName;\n" - " $query = $pathInfo['query'] ?? '';\n" - " $requestUri = $query ? \"{$documentUri}?{$query}\" : $documentUri;\n" - " $request = new HttpRequest();\n" + " $query = $pathInfo['query'] ?? '';\n" + " $requestUri = $query ? \"{$documentUri}?{$query}\" : $documentUri;\n" + " $request = new HttpRequest();\n" " $request->withDocumentRoot($root)\n" " ->withScriptFilename($path)\n" " ->withScriptName($documentUri)\n" @@ -6894,7 +6634,8 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_client = " ->withRequestUri($requestUri)\n" " ->withQueryString($query)\n" " ->withBody($data)\n" - " ->withMethod($request->getContentLength() === 0 ? 'GET' : 'POST');\n" + " ->withMethod($request->getContentLength() === 0 ? 'GET' : 'POST')\n" + " ;\n" " $response = $client->execute($request, $timeout);\n" " return $response->getBody();\n" " }\n" @@ -6904,7 +6645,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_client = " $socket = $this->socket;\n" " if ($errno !== null) {\n" " $socket->errCode = $errno;\n" - " $socket->errMsg = swoole_strerror($errno);\n" + " $socket->errMsg = swoole_strerror($errno);\n" " }\n" " $socket->close();\n" " $this->socket = null;\n" @@ -6977,8 +6718,8 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = " public function __construct(string $url, string $documentRoot = '/')\n" " {\n" " [$this->host, $this->port] = Client::parseUrl($url);\n" - " $this->documentRoot = $documentRoot;\n" - " $this->staticFileFilter = [$this, 'staticFileFiltrate'];\n" + " $this->documentRoot = $documentRoot;\n" + " $this->staticFileFilter = [$this, 'staticFileFiltrate'];\n" " }\n" "\n" " public function withTimeout(float $timeout): self\n" @@ -7043,8 +6784,8 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = " {\n" " $request = new HttpRequest();\n" " if ($userRequest instanceof \\Swoole\\Http\\Request) {\n" - " $server = $userRequest->server;\n" - " $headers = $userRequest->header;\n" + " $server = $userRequest->server;\n" + " $headers = $userRequest->header;\n" " $pathInfo = $userRequest->server['path_info'];\n" " $pathInfo = '/' . ltrim($pathInfo, '/');\n" " if (strlen($this->index) !== 0) {\n" @@ -7053,7 +6794,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = " $pathInfo = rtrim($pathInfo, '/') . '/' . $this->index;\n" " }\n" " }\n" - " $requestUri = $scriptName = $documentUri = $server['request_uri'];\n" + " $requestUri = $scriptName = $documentUri = $server['request_uri'];\n" " $queryString = $server['query_string'] ?? '';\n" " if (strlen($queryString) !== 0) {\n" " $requestUri .= \"?{$server['query_string']}\";\n" @@ -7075,12 +6816,13 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = " ->withContentLength((int) ($headers['content-length'] ?? 0))\n" " ->withHeaders($headers)\n" " ->withBody($userRequest->rawContent())\n" - " ->withAddedParams($this->params);\n" + " ->withAddedParams($this->params)\n" + " ;\n" " if ($this->https) {\n" " $request->withParam('HTTPS', '1');\n" " }\n" " } else {\n" - " throw new \\InvalidArgumentException('Not supported on ' . get_class($userRequest));\n" + " throw new \\InvalidArgumentException('Not supported on ' . $userRequest::class);\n" " }\n" " return $request;\n" " }\n" @@ -7093,7 +6835,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = " $userResponse->cookie = $response->getSetCookieHeaderLines();\n" " $userResponse->end($response->getBody());\n" " } else {\n" - " throw new \\InvalidArgumentException('Not supported on ' . get_class($userResponse));\n" + " throw new \\InvalidArgumentException('Not supported on ' . $userResponse::class);\n" " }\n" " }\n" "\n" @@ -7111,7 +6853,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = " return;\n" " }\n" " }\n" - " $client = new Client($this->host, $this->port);\n" + " $client = new Client($this->host, $this->port);\n" " $response = $client->execute($request, $this->timeout);\n" " $this->translateResponse($response, $userResponse);\n" " }\n" @@ -7123,7 +6865,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = " $extension = pathinfo($request->getScriptFilename(), PATHINFO_EXTENSION);\n" " if ($extension !== 'php') {\n" " $realPath = realpath($request->getScriptFilename());\n" - " if (!$realPath || strpos($realPath, $this->documentRoot) !== 0 || !is_file($realPath)) {\n" + " if (!$realPath || !str_starts_with($realPath, $this->documentRoot) || !is_file($realPath)) {\n" " $userResponse->status(Http\\Status::NOT_FOUND);\n" " } else {\n" " $userResponse->sendfile($realPath);\n" @@ -7132,7 +6874,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = " }\n" " return false;\n" " }\n" - " throw new \\InvalidArgumentException('Not supported on ' . get_class($userResponse));\n" + " throw new \\InvalidArgumentException('Not supported on ' . $userResponse::class);\n" " }\n" "}\n"; @@ -7276,16 +7018,16 @@ static const char* swoole_library_source_core_server_admin = "\n" " public const SIZE_OF_ZEND_ARRAY = 56;\n" "\n" - " private static $map = [\n" - " 'reactor' => SWOOLE_SERVER_COMMAND_REACTOR_THREAD,\n" + " private static array $map = [\n" + " 'reactor' => SWOOLE_SERVER_COMMAND_REACTOR_THREAD,\n" " 'reactor_thread' => SWOOLE_SERVER_COMMAND_REACTOR_THREAD,\n" - " 'worker' => SWOOLE_SERVER_COMMAND_EVENT_WORKER,\n" - " 'event_worker' => SWOOLE_SERVER_COMMAND_EVENT_WORKER,\n" - " 'task' => SWOOLE_SERVER_COMMAND_TASK_WORKER,\n" - " 'task_worker' => SWOOLE_SERVER_COMMAND_TASK_WORKER,\n" + " 'worker' => SWOOLE_SERVER_COMMAND_EVENT_WORKER,\n" + " 'event_worker' => SWOOLE_SERVER_COMMAND_EVENT_WORKER,\n" + " 'task' => SWOOLE_SERVER_COMMAND_TASK_WORKER,\n" + " 'task_worker' => SWOOLE_SERVER_COMMAND_TASK_WORKER,\n" " ];\n" "\n" - " private static $allList = [\n" + " private static array $allList = [\n" " 'all',\n" " 'all_reactor',\n" " 'all_reactor_thread',\n" @@ -7296,13 +7038,13 @@ static const char* swoole_library_source_core_server_admin = " 'specific',\n" " ];\n" "\n" - " private static $postMethodList = [\n" + " private static array $postMethodList = [\n" " 'server_reload',\n" " 'server_shutdown',\n" " 'close_session',\n" " ];\n" "\n" - " private static $accessToken = '';\n" + " private static string $accessToken = '';\n" "\n" " public static function init(Server $server)\n" " {\n" @@ -7314,7 +7056,7 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'server_reload',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" + " function (Server $server, string $msg) {\n" " $server->reload();\n" " return self::json('Operation succeeded');\n" " }\n" @@ -7323,7 +7065,7 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'server_shutdown',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" + " function (Server $server, string $msg): void {\n" " $server->shutdown();\n" " }\n" " );\n" @@ -7331,26 +7073,22 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'coroutine_stats',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json(Coroutine::stats());\n" - " }\n" + " fn (Server $server, string $msg) => self::json(Coroutine::stats())\n" " );\n" "\n" " $server->addCommand(\n" " 'coroutine_list',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json(iterator_to_array(Coroutine::list()));\n" - " }\n" + " fn (Server $server, string $msg) => self::json(iterator_to_array(Coroutine::list()))\n" " );\n" "\n" " $server->addCommand(\n" " 'coroutine_bt',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " $json = json_decode($msg);\n" - " $cid = empty($json->cid) ? 0 : intval($json->cid);\n" - " $bt = Coroutine::getBackTrace($cid);\n" + " function (Server $server, string $msg) {\n" + " $json = json_decode($msg, null, 512, JSON_THROW_ON_ERROR);\n" + " $cid = empty($json->cid) ? 0 : intval($json->cid);\n" + " $bt = Coroutine::getBackTrace($cid);\n" " if ($bt === false) {\n" " return self::json(\"Coroutine#{$cid} not exists\", 4004);\n" " }\n" @@ -7361,20 +7099,18 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'server_stats',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json($server->stats());\n" - " }\n" + " fn (Server $server, string $msg) => self::json($server->stats())\n" " );\n" "\n" " $server->addCommand(\n" " 'server_setting',\n" " $accepted_process_types,\n" - " function (Server $server, $msg) {\n" - " $setting = $server->setting;\n" - " $setting['mode'] = $server->mode;\n" - " $setting['host'] = $server->host;\n" - " $setting['port'] = $server->port;\n" - " $setting['master_pid'] = $server->master_pid;\n" + " function (Server $server, string $msg) {\n" + " $setting = $server->setting;\n" + " $setting['mode'] = $server->mode;\n" + " $setting['host'] = $server->host;\n" + " $setting['port'] = $server->port;\n" + " $setting['master_pid'] = $server->master_pid;\n" " $setting['manager_pid'] = $server->manager_pid;\n" " return self::json($setting);\n" " }\n" @@ -7383,8 +7119,8 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'get_client_info',\n" " $accepted_process_types,\n" - " function (Server $server, $msg) {\n" - " $json = json_decode($msg, true);\n" + " function (Server $server, string $msg) {\n" + " $json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);\n" " if (empty($json['session_id'])) {\n" " return self::json('require session_id', 4003);\n" " }\n" @@ -7392,39 +7128,38 @@ static const char* swoole_library_source_core_server_admin = " }\n" " );\n" "\n" - " $server->addCommand('close_session', $accepted_process_types, [__CLASS__, 'handlerCloseSession']);\n" - " $server->addCommand('get_version_info', $accepted_process_types, [__CLASS__, 'handlerGetVersionInfo']);\n" - " $server->addCommand('get_worker_info', $accepted_process_types, [__CLASS__, 'handlerGetWorkerInfo']);\n" - " $server->addCommand('get_timer_list', $accepted_process_types, [__CLASS__, 'handlerGetTimerList']);\n" - " $server->addCommand('get_coroutine_list', $accepted_process_types, [__CLASS__, 'handlerGetCoroutineList']);\n" - " $server->addCommand('get_objects', $accepted_process_types, [__CLASS__, 'handlerGetObjects']);\n" - " $server->addCommand('get_class_info', $accepted_process_types, [__CLASS__, 'handlerGetClassInfo']);\n" - " $server->addCommand('get_function_info', $accepted_process_types, [__CLASS__, 'handlerGetFunctionInfo']);\n" - " $server->addCommand('get_object_by_handle', $accepted_process_types, [__CLASS__, 'handlerGetObjectByHandle']);\n" - " $server->addCommand('get_server_cpu_usage', $accepted_process_types, [__CLASS__, 'handlerGetServerCpuUsage']);\n" + " $server->addCommand('close_session', $accepted_process_types, [self::class, 'handlerCloseSession']);\n" + " $server->addCommand('get_version_info', $accepted_process_types, [self::class, 'handlerGetVersionInfo']);\n" + " $server->addCommand('get_worker_info', $accepted_process_types, [self::class, 'handlerGetWorkerInfo']);\n" + " $server->addCommand('get_timer_list', $accepted_process_types, [self::class, 'handlerGetTimerList']);\n" + " $server->addCommand('get_coroutine_list', $accepted_process_types, [self::class, 'handlerGetCoroutineList']);\n" + " $server->addCommand('get_objects', $accepted_process_types, [self::class, 'handlerGetObjects']);\n" + " $server->addCommand('get_class_info', $accepted_process_types, [self::class, 'handlerGetClassInfo']);\n" + " $server->addCommand('get_function_info', $accepted_process_types, [self::class, 'handlerGetFunctionInfo']);\n" + " $server->addCommand('get_object_by_handle', $accepted_process_types, [self::class, 'handlerGetObjectByHandle']);\n" + " $server->addCommand('get_server_cpu_usage', $accepted_process_types, [self::class, 'handlerGetServerCpuUsage']);\n" " $server->addCommand(\n" " 'get_server_memory_usage',\n" " $accepted_process_types,\n" - " [__CLASS__, 'handlerGetServerMemoryUsage']\n" + " [self::class, 'handlerGetServerMemoryUsage']\n" " );\n" " $server->addCommand(\n" " 'get_static_property_value',\n" " $accepted_process_types,\n" - " [__CLASS__, 'handlerGetStaticPropertyValue']\n" + " [self::class, 'handlerGetStaticPropertyValue']\n" " );\n" " $server->addCommand(\n" " 'get_defined_functions',\n" " $accepted_process_types,\n" - " [__CLASS__, 'handlerGetDefinedFunctions']\n" + " [self::class, 'handlerGetDefinedFunctions']\n" " );\n" - " $server->addCommand('get_declared_classes', $accepted_process_types, [__CLASS__, 'handlerGetDeclaredClasses']);\n" + " $server->addCommand('get_declared_classes', $accepted_process_types, [self::class, 'handlerGetDeclaredClasses']);\n" "\n" " $server->addCommand(\n" " 'gc_status',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " $status = function_exists('gc_status') ? gc_status() : [];\n" - " return self::json($status);\n" + " function (Server $server, string $msg) {\n" + " return self::json(gc_status());\n" " }\n" " );\n" "\n" @@ -7432,45 +7167,37 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'opcache_status',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json(opcache_get_status(true));\n" - " }\n" + " fn (Server $server, string $msg) => self::json(opcache_get_status(true))\n" " );\n" " }\n" "\n" " $server->addCommand(\n" " 'getpid',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json(['pid' => posix_getpid()]);\n" - " }\n" + " fn (Server $server, string $msg) => self::json(['pid' => posix_getpid()])\n" " );\n" "\n" " $server->addCommand(\n" " 'memory_usage',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json([\n" - " 'usage' => memory_get_usage(),\n" - " 'real_usage' => memory_get_usage(true),\n" - " ]);\n" - " }\n" + " fn (Server $server, string $msg) => self::json([\n" + " 'usage' => memory_get_usage(),\n" + " 'real_usage' => memory_get_usage(true),\n" + " ])\n" " );\n" "\n" " $server->addCommand(\n" " 'get_included_files',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json(['files' => get_included_files()]);\n" - " }\n" + " fn (Server $server, string $msg) => self::json(['files' => get_included_files()])\n" " );\n" "\n" - " $server->addCommand('get_resources', $accepted_process_types, [__CLASS__, 'handlerGetResources']);\n" + " $server->addCommand('get_resources', $accepted_process_types, [self::class, 'handlerGetResources']);\n" "\n" " $server->addCommand(\n" " 'get_defined_constants',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" + " function (Server $server, string $msg) {\n" " $constants = get_defined_constants();\n" " foreach ($constants as $k => $c) {\n" " if (is_resource($c)) {\n" @@ -7485,15 +7212,15 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'get_loaded_extensions',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" + " function (Server $server, string $msg) {\n" " $extensions = get_loaded_extensions();\n" - " $list = [];\n" + " $list = [];\n" " foreach ($extensions as $key => $extension) {\n" - " $ext = new \\ReflectionExtension($extension);\n" + " $ext = new \\ReflectionExtension($extension);\n" " $list[$key] = [\n" - " 'id' => ++$key,\n" - " 'name' => $extension,\n" - " 'version' => $ext->getVersion() ?? '',\n" + " 'id' => ++$key,\n" + " 'name' => $extension,\n" + " 'version' => (string) $ext->getVersion(),\n" " ];\n" " }\n" " return self::json($list);\n" @@ -7503,24 +7230,20 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'get_declared_interfaces',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json(get_declared_interfaces());\n" - " }\n" + " fn (Server $server, string $msg) => self::json(get_declared_interfaces())\n" " );\n" "\n" " $server->addCommand(\n" " 'get_declared_traits',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" - " return self::json(get_declared_traits());\n" - " }\n" + " fn (Server $server, string $msg) => self::json(get_declared_traits())\n" " );\n" "\n" " $server->addCommand(\n" " 'get_included_file_contents',\n" " $accepted_process_types,\n" - " function (Server $server, $msg) {\n" - " $json = json_decode($msg, true);\n" + " function (Server $server, string $msg) {\n" + " $json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);\n" " if (empty($json['filename'])) {\n" " return self::json('require filename', 4003);\n" " }\n" @@ -7540,18 +7263,18 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'get_globals',\n" " $accepted_process_types,\n" - " function ($server, $msg) {\n" + " function (Server $server, string $msg) {\n" " $globals = [];\n" " foreach ($GLOBALS as $key => $item) {\n" " if ($key === 'GLOBALS') {\n" " continue;\n" " }\n" - " $type = gettype($item);\n" + " $type = gettype($item);\n" " $other = [];\n" " if ($type === 'object') {\n" " $other = [\n" - " 'class_name' => get_class($item),\n" - " 'object_id' => spl_object_id($item),\n" + " 'class_name' => $item::class,\n" + " 'object_id' => spl_object_id($item),\n" " 'object_hash' => spl_object_hash($item),\n" " ];\n" " }\n" @@ -7559,9 +7282,9 @@ static const char* swoole_library_source_core_server_admin = " $item = '';\n" " }\n" " $globals[] = [\n" - " 'key' => $key,\n" + " 'key' => $key,\n" " 'value' => $item,\n" - " 'type' => $type,\n" + " 'type' => $type,\n" " 'other' => $other,\n" " ];\n" " }\n" @@ -7572,8 +7295,8 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'get_extension_info',\n" " $accepted_process_types,\n" - " function (Server $server, $msg) {\n" - " $json = json_decode($msg, true);\n" + " function (Server $server, string $msg) {\n" + " $json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);\n" "\n" " if (empty($json['extension_name']) || !extension_loaded($json['extension_name'])) {\n" " return self::json('require extension_name', 4004);\n" @@ -7595,13 +7318,13 @@ static const char* swoole_library_source_core_server_admin = " unset($constants['NULL'], $constants['NAN'], $constants['INF']);\n" "\n" " return self::json([\n" - " 'classes' => $ext->getClassNames(),\n" - " 'version' => $ext->getVersion(),\n" - " 'constants' => $constants,\n" - " 'ini_entries' => $ext->getINIEntries(),\n" + " 'classes' => $ext->getClassNames(),\n" + " 'version' => $ext->getVersion(),\n" + " 'constants' => $constants,\n" + " 'ini_entries' => $ext->getINIEntries(),\n" " 'dependencies' => $ext->getDependencies(),\n" - " 'functions' => array_keys($ext->getFunctions()),\n" - " 'info' => trim($info),\n" + " 'functions' => array_keys($ext->getFunctions()),\n" + " 'info' => trim($info),\n" " ]);\n" " }\n" " );\n" @@ -7609,7 +7332,7 @@ static const char* swoole_library_source_core_server_admin = " $server->addCommand(\n" " 'get_composer_packages',\n" " $accepted_process_types,\n" - " function (Server $server, $msg) {\n" + " function (Server $server, string $msg) {\n" " if (!class_exists(\\Composer\\InstalledVersions::class)) {\n" " return self::json('require composer 2.0', 4003);\n" " }\n" @@ -7632,7 +7355,7 @@ static const char* swoole_library_source_core_server_admin = " $key_name = \"__root__{$key}\";\n" " }\n" " $package['root']['install_path'] = !empty($package['root']['install_path']) ? realpath($package['root']['install_path']) : '';\n" - " $list[$key_name] = $package;\n" + " $list[$key_name] = $package;\n" " }\n" " break;\n" " }\n" @@ -7646,17 +7369,18 @@ static const char* swoole_library_source_core_server_admin = " return self::$accessToken;\n" " }\n" "\n" - " public static function start(Server $server)\n" + " public static function start(Server $server): void\n" " {\n" " $admin_server_uri = swoole_string($server->setting['admin_server']);\n" " if ($admin_server_uri->startsWith('unix:/')) {\n" - " return swoole_error_log(SWOOLE_LOG_ERROR, \"admin_server[{$server->setting['admin_server']}] is not supported\");\n" + " swoole_error_log(SWOOLE_LOG_ERROR, \"admin_server[{$server->setting['admin_server']}] is not supported\");\n" + " return;\n" " }\n" "\n" " if ($admin_server_uri->contains('@')) {\n" " [$access_name, $access_secret] = $admin_server_uri->split('@', 2)->get(0)->split(':', 2)->toArray();\n" - " self::$accessToken = sha1($access_name . $access_secret);\n" - " [$host, $port] = $admin_server_uri->split('@', 2)->get(1)->split(':', 2)->toArray();\n" + " self::$accessToken = sha1($access_name . $access_secret);\n" + " [$host, $port] = $admin_server_uri->split('@', 2)->get(1)->split(':', 2)->toArray();\n" " } else {\n" " [$host, $port] = $admin_server_uri->split(':', 2)->toArray();\n" " }\n" @@ -7679,7 +7403,8 @@ static const char* swoole_library_source_core_server_admin = " $method = $req->getMethod();\n" "\n" " if ($method === 'OPTIONS') {\n" - " return $resp->end();\n" + " $resp->end();\n" + " return;\n" " }\n" "\n" " $token = self::getAccessToken();\n" @@ -7707,7 +7432,7 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " if ($cmd === 'multi') {\n" - " $body = json_decode($req->getContent(), true);\n" + " $body = json_decode($req->getContent(), true, 512, JSON_THROW_ON_ERROR);\n" " if (empty($body) || !is_array($body) || $method != 'POST') {\n" " goto _bad_process;\n" " }\n" @@ -7725,10 +7450,10 @@ static const char* swoole_library_source_core_server_admin = "\n" " if ($process->startsWith('master')) {\n" " $process_type = SWOOLE_SERVER_COMMAND_MASTER;\n" - " $process_id = 0;\n" + " $process_id = 0;\n" " } elseif ($process->startsWith('manager')) {\n" " $process_type = SWOOLE_SERVER_COMMAND_MANAGER;\n" - " $process_id = 0;\n" + " $process_id = 0;\n" " } elseif ($process->startsWith('all') || $process->equals('specific')) {\n" " if (!in_array($process->toString(), self::$allList)) {\n" " goto _bad_process;\n" @@ -7752,7 +7477,7 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " $process_type = self::$map[$array->get(0)->toString()];\n" - " $process_id = intval($array->get(1)->toString());\n" + " $process_id = intval($array->get(1)->toString());\n" " }\n" "\n" " $result = $server->command($cmd, $process_id, intval($process_type), $data, false);\n" @@ -7760,12 +7485,12 @@ static const char* swoole_library_source_core_server_admin = " $resp->end(json_encode([\n" " 'code' => swoole_last_error(),\n" " 'data' => swoole_strerror(swoole_last_error()),\n" - " ]));\n" + " ], JSON_THROW_ON_ERROR));\n" " } else {\n" " $resp->end($result);\n" " }\n" " });\n" - " $admin_server->handle('/', function (Request $req, Response $resp) use ($server) {\n" + " $admin_server->handle('/', function (Request $req, Response $resp): void {\n" " $resp->status(404);\n" " });\n" " $server->admin_server = $admin_server;\n" @@ -7773,17 +7498,15 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " /**\n" - " * @param $server Server\n" - " * @param mixed $msg\n" " * @return false|string\n" " */\n" - " public static function handlerGetResources($server, $msg)\n" + " public static function handlerGetResources(Server $server, string $msg)\n" " {\n" " $resources = get_resources();\n" - " $list = [];\n" + " $list = [];\n" " foreach ($resources as $r) {\n" " $info = [\n" - " 'id' => function_exists('get_resource_id') ? get_resource_id($r) : intval($r),\n" + " 'id' => get_resource_id($r),\n" " 'type' => get_resource_type($r),\n" " ];\n" " if ($info['type'] == 'stream') {\n" @@ -7795,36 +7518,30 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " /**\n" - " * @param $server Server\n" - " * @param mixed $msg\n" " * @return false|string\n" " */\n" - " public static function handlerGetWorkerInfo($server, $msg)\n" + " public static function handlerGetWorkerInfo(Server $server, string $msg)\n" " {\n" " $info = [\n" - " 'id' => $server->getWorkerId(),\n" - " 'pid' => $server->getWorkerPid(),\n" - " 'gc_status' => function_exists('gc_status') ? gc_status() : [],\n" - " 'memory_usage' => memory_get_usage(),\n" + " 'id' => $server->getWorkerId(),\n" + " 'pid' => $server->getWorkerPid(),\n" + " 'gc_status' => gc_status(),\n" + " 'memory_usage' => memory_get_usage(),\n" " 'memory_real_usage' => memory_get_usage(true),\n" - " 'process_status' => self::getProcessStatus(),\n" - " 'coroutine_stats' => Coroutine::stats(),\n" - " 'timer_stats' => Timer::stats(),\n" + " 'process_status' => self::getProcessStatus(),\n" + " 'coroutine_stats' => Coroutine::stats(),\n" + " 'timer_stats' => Timer::stats(),\n" + " 'vm_status' => swoole_get_vm_status(),\n" " ];\n" - " if (function_exists('swoole_get_vm_status')) {\n" - " $info['vm_status'] = swoole_get_vm_status();\n" - " }\n" " return self::json($info);\n" " }\n" "\n" " /**\n" - " * @param mixed $server\n" - " * @param mixed $msg\n" " * @return false|string\n" " */\n" - " public static function handlerCloseSession($server, $msg)\n" + " public static function handlerCloseSession(Server $server, string $msg)\n" " {\n" - " $json = json_decode($msg, true);\n" + " $json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);\n" " if (empty($json['session_id'])) {\n" " return self::json('require session_id', 4003);\n" " }\n" @@ -7835,16 +7552,14 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " /**\n" - " * @param mixed $server\n" - " * @param mixed $msg\n" " * @return false|string\n" " */\n" - " public static function handlerGetTimerList($server, $msg)\n" + " public static function handlerGetTimerList(Server $server, string $msg)\n" " {\n" " $list = [];\n" " foreach (Timer::list() as $timer_id) {\n" " $list[] = [\n" - " 'id' => $timer_id,\n" + " 'id' => $timer_id,\n" " 'info' => Timer::info($timer_id),\n" " ];\n" " }\n" @@ -7853,43 +7568,38 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " /**\n" - " * @param mixed $server\n" - " * @param mixed $msg\n" " * @return false|string\n" " */\n" - " public static function handlerGetCoroutineList($server, $msg)\n" + " public static function handlerGetCoroutineList(Server $server, string $msg)\n" " {\n" " $list = [];\n" " foreach (Coroutine::list() as $cid) {\n" " $list[] = [\n" - " 'id' => $cid,\n" - " 'elapsed' => Coroutine::getElapsed($cid),\n" + " 'id' => $cid,\n" + " 'elapsed' => Coroutine::getElapsed($cid),\n" " 'stack_usage' => Coroutine::getStackUsage($cid),\n" - " 'backTrace' => Coroutine::getBackTrace($cid, DEBUG_BACKTRACE_IGNORE_ARGS, 1),\n" + " 'backTrace' => Coroutine::getBackTrace($cid, DEBUG_BACKTRACE_IGNORE_ARGS, 1),\n" " ];\n" " }\n" "\n" " return self::json($list);\n" " }\n" "\n" - " public static function handlerGetObjects($server, $msg)\n" + " public static function handlerGetObjects(Server $server, string $msg)\n" " {\n" - " if (!function_exists('swoole_get_objects')) {\n" - " return self::json(['require ext-swoole_plus'], 5000);\n" - " }\n" - " $list = [];\n" + " $list = [];\n" " $objects = swoole_get_objects();\n" " foreach ($objects as $o) {\n" - " $class_name = get_class($o);\n" - " $class = new \\ReflectionClass($class_name);\n" - " $filename = $class->getFileName();\n" - " $line = $class->getStartLine();\n" - " $list[] = [\n" - " 'id' => spl_object_id($o),\n" - " 'hash' => spl_object_hash($o),\n" - " 'class' => $class_name,\n" - " 'filename' => $filename ?: '',\n" - " 'line' => $line ?: '',\n" + " $class_name = $o::class;\n" + " $class = new \\ReflectionClass($class_name);\n" + " $filename = $class->getFileName();\n" + " $line = $class->getStartLine();\n" + " $list[] = [\n" + " 'id' => spl_object_id($o),\n" + " 'hash' => spl_object_hash($o),\n" + " 'class' => $class_name,\n" + " 'filename' => $filename ?: '',\n" + " 'line' => $line ?: '',\n" " 'memory_size' => self::getObjectMemorySize($o),\n" " ];\n" " }\n" @@ -7897,25 +7607,21 @@ static const char* swoole_library_source_core_server_admin = " return self::json($list);\n" " }\n" "\n" - " public static function handlerGetClassInfo($server, $msg)\n" + " public static function handlerGetClassInfo(Server $server, string $msg)\n" " {\n" - " $json = json_decode($msg, true);\n" - " if (empty($json['class_name']) && empty($json['interface_name'])) {\n" - " return self::json(['error' => 'require class_name or interface_name'], 4004);\n" - " }\n" - "\n" + " $json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);\n" " if (!empty($json['class_name'])) {\n" " if (!class_exists($json['class_name'], false) && !interface_exists($json['class_name'], false)) {\n" " return self::json(\"{$json['class_name']} not exists\", 4003);\n" " }\n" " $name = $json['class_name'];\n" - " }\n" - "\n" - " if (!empty($json['interface_name'])) {\n" + " } elseif (!empty($json['interface_name'])) {\n" " if (!interface_exists($json['interface_name'], false)) {\n" " return self::json(\"{$json['interface_name']} not exists\", 4003);\n" " }\n" " $name = $json['interface_name'];\n" + " } else {\n" + " return self::json(['error' => 'require class_name or interface_name'], 4004);\n" " }\n" "\n" " $class = new \\ReflectionClass($name);\n" @@ -7926,38 +7632,38 @@ static const char* swoole_library_source_core_server_admin = " $tmp = [];\n" " foreach ($data as $k => $v) {\n" " $tmp[] = [\n" - " 'name' => $k,\n" + " 'name' => $k,\n" " 'value' => is_array($v) ? var_export($v, true) : $v,\n" - " 'type' => is_array($v) ? 'detail' : 'default',\n" + " 'type' => is_array($v) ? 'detail' : 'default',\n" " ];\n" " }\n" " return $tmp;\n" " };\n" "\n" " $tmpConstants = $class->getConstants();\n" - " $constants = $tmpConstants ? $getTmpConstants($tmpConstants) : [];\n" + " $constants = $tmpConstants ? $getTmpConstants($tmpConstants) : [];\n" "\n" " $staticProperties = [];\n" - " $properties = [];\n" - " $tmpProperties = $class->getProperties();\n" + " $properties = [];\n" + " $tmpProperties = $class->getProperties();\n" "\n" " $getTmpProperties = function ($class, $data) {\n" - " $static = [];\n" - " $noStatic = [];\n" + " $static = [];\n" + " $noStatic = [];\n" " $defaultProperties = $class->getDefaultProperties();\n" " foreach ($data as $k => $v) {\n" - " $name = $v->getName();\n" + " $name = $v->getName();\n" " $modifiers = \\Reflection::getModifierNames($v->getModifiers());\n" " if ($v->isStatic()) {\n" " $static[] = [\n" - " 'name' => $name,\n" - " 'value' => $defaultProperties[$name],\n" + " 'name' => $name,\n" + " 'value' => $defaultProperties[$name],\n" " 'modifiers' => implode(' ', $modifiers),\n" " ];\n" " } else {\n" " $noStatic[] = [\n" - " 'name' => $name,\n" - " 'value' => $defaultProperties[$name],\n" + " 'name' => $name,\n" + " 'value' => $defaultProperties[$name],\n" " 'modifiers' => implode(' ', $modifiers),\n" " ];\n" " }\n" @@ -7966,32 +7672,32 @@ static const char* swoole_library_source_core_server_admin = " };\n" "\n" " if ($tmpProperties) {\n" - " $tmpProperties = $getTmpProperties($class, $tmpProperties);\n" + " $tmpProperties = $getTmpProperties($class, $tmpProperties);\n" " $staticProperties = $tmpProperties['static'];\n" - " $properties = $tmpProperties['no_static'];\n" + " $properties = $tmpProperties['no_static'];\n" " }\n" "\n" - " $staticMethods = [];\n" - " $methods = [];\n" + " $staticMethods = [];\n" + " $methods = [];\n" " $tmpStaticMethods = $class->getMethods();\n" "\n" " $getTmpMethods = function ($data) {\n" - " $static = [];\n" + " $static = [];\n" " $noStatic = [];\n" " foreach ($data as $k => $v) {\n" - " $name = $v->getName();\n" - " $line = $v->getStartLine();\n" + " $name = $v->getName();\n" + " $line = $v->getStartLine();\n" " $modifiers = \\Reflection::getModifierNames($v->getModifiers());\n" " if ($v->isStatic()) {\n" " $static[] = [\n" - " 'name' => $name,\n" - " 'line' => $line ?: '',\n" + " 'name' => $name,\n" + " 'line' => $line ?: '',\n" " 'modifiers' => implode(' ', $modifiers),\n" " ];\n" " } else {\n" " $noStatic[] = [\n" - " 'name' => $name,\n" - " 'line' => $line ?: '',\n" + " 'name' => $name,\n" + " 'line' => $line ?: '',\n" " 'modifiers' => implode(' ', $modifiers),\n" " ];\n" " }\n" @@ -8001,34 +7707,31 @@ static const char* swoole_library_source_core_server_admin = "\n" " if ($tmpStaticMethods) {\n" " $tmpStaticMethods = $getTmpMethods($tmpStaticMethods);\n" - " $staticMethods = $tmpStaticMethods['static'];\n" - " $methods = $tmpStaticMethods['no_static'];\n" + " $staticMethods = $tmpStaticMethods['static'];\n" + " $methods = $tmpStaticMethods['no_static'];\n" " }\n" "\n" " $tmpParentClass = $class->getParentClass();\n" - " $parentClass = $tmpParentClass ? $tmpParentClass->getName() : '';\n" - "\n" - " $tmpInterface = $class->getInterfaceNames();\n" - " $interface = $tmpInterface ?? [];\n" + " $parentClass = $tmpParentClass ? $tmpParentClass->getName() : '';\n" "\n" " $data = [\n" - " 'filename' => $filename,\n" - " 'constants' => $constants,\n" + " 'filename' => $filename,\n" + " 'constants' => $constants,\n" " 'staticProperties' => $staticProperties,\n" - " 'properties' => $properties,\n" - " 'staticMethods' => $staticMethods,\n" - " 'methods' => $methods,\n" - " 'parentClass' => $parentClass,\n" - " 'interface' => $interface,\n" + " 'properties' => $properties,\n" + " 'staticMethods' => $staticMethods,\n" + " 'methods' => $methods,\n" + " 'parentClass' => $parentClass,\n" + " 'interface' => $class->getInterfaceNames(),\n" " ];\n" " return self::json($data);\n" " }\n" "\n" - " public static function handlerGetFunctionInfo($server, $msg)\n" + " public static function handlerGetFunctionInfo(Server $server, string $msg)\n" " {\n" - " $json = json_decode($msg, true);\n" + " $json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);\n" "\n" - " $className = $json['class_name'] ?? '';\n" + " $className = $json['class_name'] ?? '';\n" " $functionName = $json['function_name'] ?? '';\n" "\n" " if (empty($json) || empty($functionName)) {\n" @@ -8043,7 +7746,7 @@ static const char* swoole_library_source_core_server_admin = " if (!method_exists($className, $functionName)) {\n" " return self::json(\"{$className}->{$functionName} not exists\", 4004);\n" " }\n" - " $ref = new \\ReflectionMethod($className, $functionName);\n" + " $ref = new \\ReflectionMethod($className, $functionName);\n" " $isStatic = $ref->isStatic();\n" " } else {\n" " if (!function_exists($functionName)) {\n" @@ -8053,12 +7756,12 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " $result = [\n" - " 'filename' => $ref->getFileName(),\n" - " 'line' => $ref->getStartLine() ?? '',\n" - " 'num' => $ref->getNumberOfParameters(),\n" + " 'filename' => $ref->getFileName(),\n" + " 'line' => $ref->getStartLine() ?: '',\n" + " 'num' => $ref->getNumberOfParameters(),\n" " 'user_defined' => $ref->isUserDefined(),\n" - " 'extension' => $ref->getExtensionName(),\n" - " 'is_static' => $isStatic,\n" + " 'extension' => $ref->getExtensionName(),\n" + " 'is_static' => $isStatic,\n" " ];\n" "\n" " $params = $ref->getParameters();\n" @@ -8109,19 +7812,19 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " $isPassedByReference = $param->isPassedByReference() ? '&' : '';\n" - " $isVariadic = $param->isVariadic() ? '...' : '';\n" + " $isVariadic = $param->isVariadic() ? '...' : '';\n" "\n" " $option = \"{$optional}{$type} {$isPassedByReference}{$isVariadic}\";\n" - " $param = \"\\${$paramName}{$default}\";\n" + " $param = \"\\${$paramName}{$default}\";\n" "\n" " $list[] = [\n" - " 'optional' => $optional,\n" - " 'type' => $type,\n" + " 'optional' => $optional,\n" + " 'type' => $type,\n" " 'is_passed_by_reference' => $isPassedByReference,\n" - " 'is_variadic' => $isVariadic,\n" - " 'name' => $paramName,\n" - " 'default' => $default,\n" - " 'full' => $option !== ' ' ? \"{$option}{$param}\" : $param,\n" + " 'is_variadic' => $isVariadic,\n" + " 'name' => $paramName,\n" + " 'default' => $default,\n" + " 'full' => $option !== ' ' ? \"{$option}{$param}\" : $param,\n" " ];\n" " }\n" " $result['params'] = $list;\n" @@ -8129,13 +7832,9 @@ static const char* swoole_library_source_core_server_admin = " return self::json($result);\n" " }\n" "\n" - " public static function handlerGetObjectByHandle($server, $msg)\n" + " public static function handlerGetObjectByHandle(Server $server, string $msg)\n" " {\n" - " if (!function_exists('swoole_get_object_by_handle')) {\n" - " return self::json(['require ext-swoole_plus'], 5000);\n" - " }\n" - "\n" - " $json = json_decode($msg, true);\n" + " $json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);\n" " if (empty($json) || empty($json['object_id']) || empty($json['object_hash'])) {\n" " return self::json(['error' => 'Params Error!'], 4004);\n" " }\n" @@ -8153,11 +7852,11 @@ static const char* swoole_library_source_core_server_admin = " return self::json(var_export($object, true));\n" " }\n" "\n" - " public static function handlerGetVersionInfo($server, $msg)\n" + " public static function handlerGetVersionInfo(Server $server, string $msg)\n" " {\n" " $ip_arr = swoole_get_local_ip();\n" - " $host = [];\n" - " $local = [];\n" + " $host = [];\n" + " $local = [];\n" " foreach ($ip_arr as $k => $ip) {\n" " if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {\n" " $host[] = $ip;\n" @@ -8166,55 +7865,55 @@ static const char* swoole_library_source_core_server_admin = " }\n" " }\n" " $data = [\n" - " 'os' => php_uname('s') . '-' . php_uname('r'),\n" + " 'os' => php_uname('s') . '-' . php_uname('r'),\n" " 'swoole' => swoole_version(),\n" - " 'php' => phpversion(),\n" - " 'ip' => $host ? $host[0] : $local[0],\n" + " 'php' => phpversion(),\n" + " 'ip' => $host ? $host[0] : $local[0],\n" " ];\n" " return self::json($data);\n" " }\n" "\n" - " public static function handlerGetDefinedFunctions($server, $msg)\n" + " public static function handlerGetDefinedFunctions(Server $server, string $msg)\n" " {\n" " $functions = get_defined_functions();\n" - " $arr = [];\n" - " if ($functions) {\n" - " $arr['internal'] = $functions['internal'];\n" - "\n" + " $arr = [\n" + " 'internal' => $functions['internal'],\n" + " ];\n" + " if (!empty($functions['user'])) {\n" " foreach ($functions['user'] as $function_name) {\n" - " $function = new \\ReflectionFunction($function_name);\n" - " $filename = $function->getFileName();\n" - " $line = $function->getStartLine();\n" + " $function = new \\ReflectionFunction($function_name);\n" + " $filename = $function->getFileName();\n" + " $line = $function->getStartLine();\n" " $arr['user'][] = [\n" " 'function' => $function_name,\n" " 'filename' => $filename,\n" - " 'line' => $line,\n" + " 'line' => $line,\n" " ];\n" " }\n" " }\n" " return self::json($arr);\n" " }\n" "\n" - " public static function handlerGetDeclaredClasses($server, $msg)\n" + " public static function handlerGetDeclaredClasses(Server $server, string $msg)\n" " {\n" " $classes = get_declared_classes();\n" - " $arr = [];\n" + " $arr = [];\n" " if ($classes) {\n" " foreach ($classes as $classes_name) {\n" " $function = new \\ReflectionClass($classes_name);\n" " $filename = $function->getFileName();\n" - " $line = $function->getStartLine();\n" - " $arr[] = [\n" - " 'class' => $classes_name,\n" + " $line = $function->getStartLine();\n" + " $arr[] = [\n" + " 'class' => $classes_name,\n" " 'filename' => $filename ?: '',\n" - " 'line' => $line ?: '',\n" + " 'line' => $line ?: '',\n" " ];\n" " }\n" " }\n" " return self::json($arr);\n" " }\n" "\n" - " public static function handlerGetServerMemoryUsage($server, $msg)\n" + " public static function handlerGetServerMemoryUsage(Server $server, string $msg)\n" " {\n" " $total = 0;\n" "\n" @@ -8230,8 +7929,9 @@ static const char* swoole_library_source_core_server_admin = " $total += $result['manager'];\n" "\n" " $n = $server->setting['worker_num'] + $server->setting['task_worker_num'];\n" + " /** @var int $n */\n" " for ($i = 0; $i < $n; $i++) {\n" - " $key = 'worker-' . $i;\n" + " $key = 'worker-' . $i;\n" " $result[$key] = self::getProcessMemoryRealUsage($server->getWorkerPid($i));\n" " $total += $result[$key];\n" " }\n" @@ -8242,13 +7942,13 @@ static const char* swoole_library_source_core_server_admin = " // TODO: Support other OS\n" " if (PHP_OS_FAMILY === 'Linux') {\n" " preg_match('#MemTotal:\\s+(\\d+) kB#i', file_get_contents('/proc/meminfo'), $match);\n" - " $result['memory_size'] = $match[1] * 1024;\n" + " $result['memory_size'] = intval($match[1]) * 1024;\n" " }\n" "\n" " return self::json($result);\n" " }\n" "\n" - " public static function handlerGetServerCpuUsage($server, $msg)\n" + " public static function handlerGetServerCpuUsage(Server $server, string $msg)\n" " {\n" " $total = 0;\n" "\n" @@ -8266,21 +7966,22 @@ static const char* swoole_library_source_core_server_admin = " $total += $result['manager'][1] ?? 0;\n" "\n" " $n = $server->setting['worker_num'] + $server->setting['task_worker_num'];\n" + " /** @var int $n */\n" " for ($i = 0; $i < $n; $i++) {\n" - " $key = 'worker-' . $i;\n" + " $key = 'worker-' . $i;\n" " $result[$key] = self::getProcessCpuUsage($server->getWorkerPid($i))[1] ?? 0;\n" " $total += $result[$key];\n" " }\n" "\n" - " $result['total'] = $total;\n" + " $result['total'] = $total;\n" " $result['cpu_num'] = swoole_cpu_num();\n" "\n" " return self::json($result);\n" " }\n" "\n" - " public static function handlerGetStaticPropertyValue($server, $msg)\n" + " public static function handlerGetStaticPropertyValue(Server $server, string $msg)\n" " {\n" - " $json = json_decode($msg, true);\n" + " $json = json_decode($msg, true, 512, JSON_THROW_ON_ERROR);\n" " if (empty($json['class_name'])) {\n" " return self::json(['error' => 'require class_name!'], 4004);\n" " }\n" @@ -8288,7 +7989,7 @@ static const char* swoole_library_source_core_server_admin = " return self::json(['error' => 'require property_name!'], 4004);\n" " }\n" "\n" - " $className = $json['class_name'];\n" + " $className = $json['class_name'];\n" " $propertyName = $json['property_name'];\n" "\n" " if (!class_exists($className)) {\n" @@ -8296,7 +7997,7 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " $reflection = new \\ReflectionClass($className);\n" - " $value = $reflection->getStaticPropertyValue($propertyName, []);\n" + " $value = $reflection->getStaticPropertyValue($propertyName, []);\n" "\n" " $result = [\n" " 'value' => var_export($value, true),\n" @@ -8309,7 +8010,7 @@ static const char* swoole_library_source_core_server_admin = " $return_list = [];\n" " foreach ($list as $key => $content) {\n" " $path_array = swoole_string($content['path'])->trim('/')->split('/');\n" - " $cmd = $path_array->get(1)->toString();\n" + " $cmd = $path_array->get(1)->toString();\n" "\n" " if ($path_array->count() == 2) {\n" " $process = swoole_string('master');\n" @@ -8317,7 +8018,7 @@ static const char* swoole_library_source_core_server_admin = " $process = $path_array->get(2);\n" " }\n" "\n" - " $data = [];\n" + " $data = [];\n" " $url_query = parse_url($process->toString(), PHP_URL_QUERY) ?? [];\n" " if (!empty($url_query)) {\n" " parse_str($url_query, $data);\n" @@ -8326,10 +8027,10 @@ static const char* swoole_library_source_core_server_admin = "\n" " if ($process->startsWith('master')) {\n" " $process_type = SWOOLE_SERVER_COMMAND_MASTER;\n" - " $process_id = 0;\n" + " $process_id = 0;\n" " } elseif ($process->startsWith('manager')) {\n" " $process_type = SWOOLE_SERVER_COMMAND_MANAGER;\n" - " $process_id = 0;\n" + " $process_id = 0;\n" " } elseif ($process->startsWith('all') || $process->startsWith('specific')) {\n" " if (!in_array($process->toString(), self::$allList) && !$process->startsWith('specific')) {\n" " $return_list[$key] = json_decode('{}');\n" @@ -8349,7 +8050,7 @@ static const char* swoole_library_source_core_server_admin = " }\n" "\n" " $process_type = self::$map[$array->get(0)->toString()];\n" - " $process_id = intval($array->get(1)->toString());\n" + " $process_id = intval($array->get(1)->toString());\n" " }\n" "\n" " $return_list[$key] = $server->command($cmd, $process_id, intval($process_type), $data, true);\n" @@ -8386,8 +8087,8 @@ static const char* swoole_library_source_core_server_admin = " if ($array->count() != 2 || !isset(self::$map[$array->get(0)->toString()])) {\n" " $result[$name] = $json_decode ? json_decode('{}') : $json_decode;\n" " } else {\n" - " $process_type = self::$map[$array->get(0)->toString()];\n" - " $process_id = intval($array->get(1)->toString());\n" + " $process_type = self::$map[$array->get(0)->toString()];\n" + " $process_id = intval($array->get(1)->toString());\n" " $result[$name] = $server->command($cmd, $process_id, $process_type, $data, $json_decode);\n" " }\n" " }\n" @@ -8431,8 +8132,8 @@ static const char* swoole_library_source_core_server_admin = " private static function handlerGetAllWorker($cmd, $data, Server $server, bool $json_decode = false)\n" " {\n" " $process_type = SWOOLE_SERVER_COMMAND_EVENT_WORKER;\n" - " $worker_num = $server->setting['worker_num'];\n" - " $list = [];\n" + " $worker_num = $server->setting['worker_num'];\n" + " $list = [];\n" " for ($process_id = 0; $process_id < $worker_num; $process_id++) {\n" " $list[\"worker-{$process_id}\"] = $server->command($cmd, $process_id, $process_type, $data, $json_decode);\n" " }\n" @@ -8442,7 +8143,7 @@ static const char* swoole_library_source_core_server_admin = " private static function handlerGetAllTaskWorker($cmd, $data, Server $server, bool $json_decode = false)\n" " {\n" " $process_type = SWOOLE_SERVER_COMMAND_TASK_WORKER;\n" - " $list = [];\n" + " $list = [];\n" " if (empty($server->setting['task_worker_num'])) {\n" " return $list;\n" " }\n" @@ -8460,7 +8161,7 @@ static const char* swoole_library_source_core_server_admin = " return [0];\n" " }\n" "\n" - " $statAll = file_get_contents('/proc/stat');\n" + " $statAll = file_get_contents('/proc/stat');\n" " $statProc = file_get_contents(\"/proc/{$pid}/stat\");\n" "\n" " $dataAll = preg_split(\"/[ \\t]+/\", $statAll, 6);\n" @@ -8493,12 +8194,12 @@ static const char* swoole_library_source_core_server_admin = " return $array;\n" " }\n" " $status = swoole_string(trim(file_get_contents(\"/proc/{$pid}/status\")));\n" - " $lines = $status->split(\"\\n\");\n" + " $lines = $status->split(\"\\n\");\n" " foreach ($lines as $l) {\n" " if (empty($l)) {\n" " continue;\n" " }\n" - " [$k, $v] = swoole_string($l)->split(':');\n" + " [$k, $v] = swoole_string($l)->split(':');\n" " $array[$k] = trim($v);\n" " }\n" " return $array;\n" @@ -8592,194 +8293,194 @@ static const char* swoole_library_source_core_server_helper = "\n" "namespace Swoole\\Server;\n" "\n" + "use Swoole\\Constant;\n" + "use Swoole\\Coroutine;\n" "use Swoole\\Server;\n" "use Swoole\\Timer;\n" "\n" - "use function Swoole\\Coroutine\\go;\n" - "\n" "class Helper\n" "{\n" " public const STATS_TIMER_INTERVAL_TIME = 1000;\n" "\n" " public const GLOBAL_OPTIONS = [\n" - " 'debug_mode' => true,\n" - " 'trace_flags' => true,\n" - " 'log_file' => true,\n" - " 'log_level' => true,\n" - " 'log_date_format' => true,\n" - " 'log_date_with_microseconds' => true,\n" - " 'log_rotation' => true,\n" - " 'display_errors' => true,\n" - " 'dns_server' => true,\n" - " 'socket_dns_timeout' => true,\n" - " 'socket_connect_timeout' => true,\n" - " 'socket_write_timeout' => true,\n" - " 'socket_send_timeout' => true,\n" - " 'socket_read_timeout' => true,\n" - " 'socket_recv_timeout' => true,\n" - " 'socket_buffer_size' => true,\n" - " 'socket_timeout' => true,\n" - " 'http2_header_table_size' => true,\n" - " 'http2_enable_push' => true,\n" + " 'debug_mode' => true,\n" + " 'trace_flags' => true,\n" + " 'log_file' => true,\n" + " 'log_level' => true,\n" + " 'log_date_format' => true,\n" + " 'log_date_with_microseconds' => true,\n" + " 'log_rotation' => true,\n" + " 'display_errors' => true,\n" + " 'dns_server' => true,\n" + " 'socket_dns_timeout' => true,\n" + " 'socket_connect_timeout' => true,\n" + " 'socket_write_timeout' => true,\n" + " 'socket_send_timeout' => true,\n" + " 'socket_read_timeout' => true,\n" + " 'socket_recv_timeout' => true,\n" + " 'socket_buffer_size' => true,\n" + " 'socket_timeout' => true,\n" + " 'http2_header_table_size' => true,\n" + " 'http2_enable_push' => true,\n" " 'http2_max_concurrent_streams' => true,\n" - " 'http2_init_window_size' => true,\n" - " 'http2_max_frame_size' => true,\n" - " 'http2_max_header_list_size' => true,\n" + " 'http2_init_window_size' => true,\n" + " 'http2_max_frame_size' => true,\n" + " 'http2_max_header_list_size' => true,\n" " ];\n" "\n" " public const SERVER_OPTIONS = [\n" - " 'chroot' => true,\n" - " 'user' => true,\n" - " 'group' => true,\n" - " 'daemonize' => true,\n" - " 'pid_file' => true,\n" - " 'reactor_num' => true,\n" - " 'single_thread' => true,\n" - " 'worker_num' => true,\n" - " 'max_wait_time' => true,\n" - " 'max_queued_bytes' => true,\n" - " 'max_concurrency' => true,\n" - " 'worker_max_concurrency' => true,\n" - " 'enable_coroutine' => true,\n" - " 'send_timeout' => true,\n" - " 'dispatch_mode' => true,\n" - " 'send_yield' => true,\n" - " 'dispatch_func' => true,\n" - " 'discard_timeout_request' => true,\n" - " 'enable_unsafe_event' => true,\n" - " 'enable_delay_receive' => true,\n" - " 'enable_reuse_port' => true,\n" - " 'task_use_object' => true,\n" - " 'task_object' => true,\n" - " 'event_object' => true,\n" - " 'task_enable_coroutine' => true,\n" - " 'task_worker_num' => true,\n" - " 'task_ipc_mode' => true,\n" - " 'task_tmpdir' => true,\n" - " 'task_max_request' => true,\n" - " 'task_max_request_grace' => true,\n" - " 'max_connection' => true,\n" - " 'max_conn' => true,\n" - " 'start_session_id' => true,\n" - " 'heartbeat_check_interval' => true,\n" - " 'heartbeat_idle_time' => true,\n" - " 'max_request' => true,\n" - " 'max_request_grace' => true,\n" - " 'reload_async' => true,\n" - " 'open_cpu_affinity' => true,\n" - " 'cpu_affinity_ignore' => true,\n" - " 'http_parse_cookie' => true,\n" - " 'http_parse_post' => true,\n" - " 'http_parse_files' => true,\n" - " 'http_compression' => true,\n" - " 'http_compression_level' => true,\n" - " 'compression_level' => true,\n" - " 'http_gzip_level' => true,\n" + " 'chroot' => true,\n" + " 'user' => true,\n" + " 'group' => true,\n" + " 'daemonize' => true,\n" + " 'pid_file' => true,\n" + " 'reactor_num' => true,\n" + " 'single_thread' => true,\n" + " 'worker_num' => true,\n" + " 'max_wait_time' => true,\n" + " 'max_queued_bytes' => true,\n" + " 'max_concurrency' => true,\n" + " 'worker_max_concurrency' => true,\n" + " 'enable_coroutine' => true,\n" + " 'send_timeout' => true,\n" + " 'dispatch_mode' => true,\n" + " 'send_yield' => true,\n" + " 'dispatch_func' => true,\n" + " 'discard_timeout_request' => true,\n" + " 'enable_unsafe_event' => true,\n" + " 'enable_delay_receive' => true,\n" + " 'enable_reuse_port' => true,\n" + " 'task_use_object' => true,\n" + " 'task_object' => true,\n" + " 'event_object' => true,\n" + " 'task_enable_coroutine' => true,\n" + " 'task_worker_num' => true,\n" + " 'task_ipc_mode' => true,\n" + " 'task_tmpdir' => true,\n" + " 'task_max_request' => true,\n" + " 'task_max_request_grace' => true,\n" + " 'max_connection' => true,\n" + " 'max_conn' => true,\n" + " 'start_session_id' => true,\n" + " 'heartbeat_check_interval' => true,\n" + " 'heartbeat_idle_time' => true,\n" + " 'max_request' => true,\n" + " 'max_request_grace' => true,\n" + " 'reload_async' => true,\n" + " 'open_cpu_affinity' => true,\n" + " 'cpu_affinity_ignore' => true,\n" + " 'http_parse_cookie' => true,\n" + " 'http_parse_post' => true,\n" + " 'http_parse_files' => true,\n" + " 'http_compression' => true,\n" + " 'http_compression_level' => true,\n" + " 'compression_level' => true,\n" + " 'http_gzip_level' => true,\n" " 'http_compression_min_length' => true,\n" - " 'compression_min_length' => true,\n" - " 'websocket_compression' => true,\n" - " 'upload_tmp_dir' => true,\n" - " 'upload_max_filesize' => true,\n" - " 'enable_static_handler' => true,\n" - " 'document_root' => true,\n" - " 'http_autoindex' => true,\n" - " 'http_index_files' => true,\n" - " 'http_compression_types' => true,\n" - " 'compression_types' => true,\n" - " 'static_handler_locations' => true,\n" - " 'input_buffer_size' => true,\n" - " 'buffer_input_size' => true,\n" - " 'output_buffer_size' => true,\n" - " 'buffer_output_size' => true,\n" - " 'message_queue_key' => true,\n" + " 'compression_min_length' => true,\n" + " 'websocket_compression' => true,\n" + " 'upload_tmp_dir' => true,\n" + " 'upload_max_filesize' => true,\n" + " 'enable_static_handler' => true,\n" + " 'document_root' => true,\n" + " 'http_autoindex' => true,\n" + " 'http_index_files' => true,\n" + " 'http_compression_types' => true,\n" + " 'compression_types' => true,\n" + " 'static_handler_locations' => true,\n" + " 'input_buffer_size' => true,\n" + " 'buffer_input_size' => true,\n" + " 'output_buffer_size' => true,\n" + " 'buffer_output_size' => true,\n" + " 'message_queue_key' => true,\n" " ];\n" "\n" " public const PORT_OPTIONS = [\n" - " 'ssl_cert_file' => true,\n" - " 'ssl_key_file' => true,\n" - " 'backlog' => true,\n" - " 'socket_buffer_size' => true,\n" + " 'ssl_cert_file' => true,\n" + " 'ssl_key_file' => true,\n" + " 'backlog' => true,\n" + " 'socket_buffer_size' => true,\n" " 'kernel_socket_recv_buffer_size' => true,\n" " 'kernel_socket_send_buffer_size' => true,\n" - " 'heartbeat_idle_time' => true,\n" - " 'buffer_high_watermark' => true,\n" - " 'buffer_low_watermark' => true,\n" - " 'open_tcp_nodelay' => true,\n" - " 'tcp_defer_accept' => true,\n" - " 'open_tcp_keepalive' => true,\n" - " 'open_eof_check' => true,\n" - " 'open_eof_split' => true,\n" - " 'package_eof' => true,\n" - " 'open_http_protocol' => true,\n" - " 'open_websocket_protocol' => true,\n" - " 'websocket_subprotocol' => true,\n" - " 'open_websocket_close_frame' => true,\n" - " 'open_websocket_ping_frame' => true,\n" - " 'open_websocket_pong_frame' => true,\n" - " 'open_http2_protocol' => true,\n" - " 'open_mqtt_protocol' => true,\n" - " 'open_redis_protocol' => true,\n" - " 'max_idle_time' => true,\n" - " 'tcp_keepidle' => true,\n" - " 'tcp_keepinterval' => true,\n" - " 'tcp_keepcount' => true,\n" - " 'tcp_user_timeout' => true,\n" - " 'tcp_fastopen' => true,\n" - " 'open_length_check' => true,\n" - " 'package_length_type' => true,\n" - " 'package_length_offset' => true,\n" - " 'package_body_offset' => true,\n" - " 'package_body_start' => true,\n" - " 'package_length_func' => true,\n" - " 'package_max_length' => true,\n" - " 'ssl_compress' => true,\n" - " 'ssl_protocols' => true,\n" - " 'ssl_verify_peer' => true,\n" - " 'ssl_allow_self_signed' => true,\n" - " 'ssl_client_cert_file' => true,\n" - " 'ssl_verify_depth' => true,\n" - " 'ssl_prefer_server_ciphers' => true,\n" - " 'ssl_ciphers' => true,\n" - " 'ssl_ecdh_curve' => true,\n" - " 'ssl_dhparam' => true,\n" - " 'ssl_sni_certs' => true,\n" + " 'heartbeat_idle_time' => true,\n" + " 'buffer_high_watermark' => true,\n" + " 'buffer_low_watermark' => true,\n" + " 'open_tcp_nodelay' => true,\n" + " 'tcp_defer_accept' => true,\n" + " 'open_tcp_keepalive' => true,\n" + " 'open_eof_check' => true,\n" + " 'open_eof_split' => true,\n" + " 'package_eof' => true,\n" + " 'open_http_protocol' => true,\n" + " 'open_websocket_protocol' => true,\n" + " 'websocket_subprotocol' => true,\n" + " 'open_websocket_close_frame' => true,\n" + " 'open_websocket_ping_frame' => true,\n" + " 'open_websocket_pong_frame' => true,\n" + " 'open_http2_protocol' => true,\n" + " 'open_mqtt_protocol' => true,\n" + " 'open_redis_protocol' => true,\n" + " 'max_idle_time' => true,\n" + " 'tcp_keepidle' => true,\n" + " 'tcp_keepinterval' => true,\n" + " 'tcp_keepcount' => true,\n" + " 'tcp_user_timeout' => true,\n" + " 'tcp_fastopen' => true,\n" + " 'open_length_check' => true,\n" + " 'package_length_type' => true,\n" + " 'package_length_offset' => true,\n" + " 'package_body_offset' => true,\n" + " 'package_body_start' => true,\n" + " 'package_length_func' => true,\n" + " 'package_max_length' => true,\n" + " 'ssl_compress' => true,\n" + " 'ssl_protocols' => true,\n" + " 'ssl_verify_peer' => true,\n" + " 'ssl_allow_self_signed' => true,\n" + " 'ssl_client_cert_file' => true,\n" + " 'ssl_verify_depth' => true,\n" + " 'ssl_prefer_server_ciphers' => true,\n" + " 'ssl_ciphers' => true,\n" + " 'ssl_ecdh_curve' => true,\n" + " 'ssl_dhparam' => true,\n" + " 'ssl_sni_certs' => true,\n" " ];\n" "\n" " public const AIO_OPTIONS = [\n" - " 'aio_core_worker_num' => true,\n" - " 'aio_worker_num' => true,\n" - " 'aio_max_wait_time' => true,\n" - " 'aio_max_idle_time' => true,\n" - " 'enable_signalfd' => true,\n" - " 'wait_signal' => true,\n" + " 'aio_core_worker_num' => true,\n" + " 'aio_worker_num' => true,\n" + " 'aio_max_wait_time' => true,\n" + " 'aio_max_idle_time' => true,\n" + " 'enable_signalfd' => true,\n" + " 'wait_signal' => true,\n" " 'dns_cache_refresh_time' => true,\n" - " 'thread_num' => true,\n" - " 'min_thread_num' => true,\n" - " 'max_thread_num' => true,\n" - " 'socket_dontwait' => true,\n" - " 'dns_lookup_random' => true,\n" - " 'use_async_resolver' => true,\n" - " 'enable_coroutine' => true,\n" + " 'thread_num' => true,\n" + " 'min_thread_num' => true,\n" + " 'max_thread_num' => true,\n" + " 'socket_dontwait' => true,\n" + " 'dns_lookup_random' => true,\n" + " 'use_async_resolver' => true,\n" + " 'enable_coroutine' => true,\n" " ];\n" "\n" " public const COROUTINE_OPTIONS = [\n" - " 'max_coro_num' => true,\n" - " 'max_coroutine' => true,\n" - " 'enable_deadlock_check' => true,\n" - " 'hook_flags' => true,\n" + " 'max_coro_num' => true,\n" + " 'max_coroutine' => true,\n" + " 'enable_deadlock_check' => true,\n" + " 'hook_flags' => true,\n" " 'enable_preemptive_scheduler' => true,\n" - " 'c_stack_size' => true,\n" - " 'stack_size' => true,\n" - " 'name_resolver' => true,\n" - " 'dns_cache_expire' => true,\n" - " 'dns_cache_capacity' => true,\n" - " 'max_concurrency' => true,\n" + " 'c_stack_size' => true,\n" + " 'stack_size' => true,\n" + " 'name_resolver' => true,\n" + " 'dns_cache_expire' => true,\n" + " 'dns_cache_capacity' => true,\n" + " 'max_concurrency' => true,\n" " ];\n" "\n" " public const HELPER_OPTIONS = [\n" - " 'stats_file' => true,\n" + " 'stats_file' => true,\n" " 'stats_timer_interval' => true,\n" - " 'admin_server' => true,\n" + " 'admin_server' => true,\n" " ];\n" "\n" " public static function checkOptions(array $input_options)\n" @@ -8805,7 +8506,7 @@ static const char* swoole_library_source_core_server_helper = "\n" " public static function onBeforeShutdown(Server $server)\n" " {\n" - " if ($server->admin_server) {\n" + " if ($server->admin_server) { // @phpstan-ignore if.alwaysTrue\n" " $server->admin_server->shutdown();\n" " $server->admin_server = null;\n" " }\n" @@ -8817,10 +8518,10 @@ static const char* swoole_library_source_core_server_helper = " $interval_ms = empty($server->setting['stats_timer_interval']) ? self::STATS_TIMER_INTERVAL_TIME : intval($server->setting['stats_timer_interval']);\n" "\n" " $server->stats_timer = Timer::tick($interval_ms, function () use ($server) {\n" - " $stats = $server->stats();\n" + " $stats = $server->stats();\n" " $stats_file = swoole_string($server->setting['stats_file']);\n" " if ($stats_file->endsWith('.json')) {\n" - " $out = json_encode($stats);\n" + " $out = json_encode($stats, JSON_THROW_ON_ERROR);\n" " } elseif ($stats_file->endsWith('.php')) {\n" " $out = \"setting['admin_server'])) {\n" - " go(function () use ($server) {\n" + " if (!empty($server->setting[Constant::OPTION_ADMIN_SERVER])) {\n" + " Coroutine::create(function () use ($server): void {\n" " Admin::start($server);\n" " });\n" " }\n" @@ -8903,16 +8604,13 @@ static const char* swoole_library_source_core_name_resolver = "{\n" " protected $baseUrl;\n" "\n" - " protected $prefix;\n" - "\n" " protected $info;\n" "\n" " private $filter_fn;\n" "\n" - " public function __construct($url, $prefix = 'swoole_service_')\n" + " public function __construct($url, protected $prefix = 'swoole_service_')\n" " {\n" " $this->checkServerUrl($url);\n" - " $this->prefix = $prefix;\n" " }\n" "\n" " abstract public function join(string $name, string $ip, int $port, array $options = []): bool;\n" @@ -8942,7 +8640,7 @@ static const char* swoole_library_source_core_name_resolver = " * and an empty string indicates name lookup failed, and lookup operation will not continue.\n" " * return Cluster: has multiple nodes and failover is possible\n" " * return false or null: try another name resolver\n" - " * @return null|Cluster|false|string\n" + " * @return Cluster|false|string|null\n" " */\n" " public function lookup(string $name)\n" " {\n" @@ -8963,9 +8661,8 @@ static const char* swoole_library_source_core_name_resolver = "\n" " /**\n" " * !!! The host MUST BE IP ADDRESS\n" - " * @param mixed $url\n" " */\n" - " protected function checkServerUrl($url)\n" + " protected function checkServerUrl(string $url)\n" " {\n" " $info = parse_url($url);\n" " if (empty($info['scheme']) or empty($info['host'])) {\n" @@ -8987,15 +8684,10 @@ static const char* swoole_library_source_core_name_resolver = " $baseUrl .= rtrim($info['path'], '/');\n" " }\n" " $this->baseUrl = $baseUrl;\n" - " $this->info = $info;\n" + " $this->info = $info;\n" " }\n" "\n" - " /**\n" - " * @param $r ClientProxy\n" - " * @param mixed $url\n" - " * @return bool\n" - " */\n" - " protected function checkResponse($r, $url)\n" + " protected function checkResponse(?ClientProxy $r, string $url): bool\n" " {\n" " if (empty($r)) {\n" " throw new Exception(\"failed to request URL({$url})\");\n" @@ -9059,10 +8751,7 @@ static const char* swoole_library_source_core_name_resolver_cluster = "\n" "class Cluster\n" "{\n" - " /**\n" - " * @var array\n" - " */\n" - " private $nodes = [];\n" + " private array $nodes = [];\n" "\n" " /**\n" " * @throws Exception\n" @@ -9090,7 +8779,7 @@ static const char* swoole_library_source_core_name_resolver_cluster = " return false;\n" " }\n" " $index = array_rand($this->nodes, 1);\n" - " $node = $this->nodes[$index];\n" + " $node = $this->nodes[$index];\n" " unset($this->nodes[$index]);\n" " return $node;\n" " }\n" @@ -9217,16 +8906,16 @@ static const char* swoole_library_source_core_name_resolver_nacos = " */\n" " public function join(string $name, string $ip, int $port, array $options = []): bool\n" " {\n" - " $params['port'] = $port;\n" - " $params['ip'] = $ip;\n" - " $params['healthy'] = 'true';\n" - " $params['weight'] = $options['weight'] ?? 100;\n" - " $params['encoding'] = $options['encoding'] ?? 'utf-8';\n" + " $params['port'] = $port;\n" + " $params['ip'] = $ip;\n" + " $params['healthy'] = 'true';\n" + " $params['weight'] = $options['weight'] ?? 100;\n" + " $params['encoding'] = $options['encoding'] ?? 'utf-8';\n" " $params['namespaceId'] = $options['namespaceId'] ?? 'public';\n" " $params['serviceName'] = $this->prefix . $name;\n" "\n" " $url = $this->baseUrl . '/nacos/v1/ns/instance?' . http_build_query($params);\n" - " $r = Coroutine\\Http\\post($url, []);\n" + " $r = Coroutine\\Http\\post($url, []);\n" " return $this->checkResponse($r, $url);\n" " }\n" "\n" @@ -9235,12 +8924,12 @@ static const char* swoole_library_source_core_name_resolver_nacos = " */\n" " public function leave(string $name, string $ip, int $port): bool\n" " {\n" - " $params['port'] = $port;\n" - " $params['ip'] = $ip;\n" + " $params['port'] = $port;\n" + " $params['ip'] = $ip;\n" " $params['serviceName'] = $this->prefix . $name;\n" "\n" " $url = $this->baseUrl . '/nacos/v1/ns/instance?' . http_build_query($params);\n" - " $r = Coroutine\\Http\\request($this->baseUrl . '/nacos/v1/ns/instance?' . http_build_query($params), 'DELETE');\n" + " $r = Coroutine\\Http\\request($this->baseUrl . '/nacos/v1/ns/instance?' . http_build_query($params), 'DELETE');\n" " return $this->checkResponse($r, $url);\n" " }\n" "\n" @@ -9252,11 +8941,11 @@ static const char* swoole_library_source_core_name_resolver_nacos = " $params['serviceName'] = $this->prefix . $name;\n" "\n" " $url = $this->baseUrl . '/nacos/v1/ns/instance/list?' . http_build_query($params);\n" - " $r = Coroutine\\Http\\get($url);\n" + " $r = Coroutine\\Http\\get($url);\n" " if (!$this->checkResponse($r, $url)) {\n" " return null;\n" " }\n" - " $result = json_decode($r->getBody());\n" + " $result = json_decode($r->getBody(), null, 512, JSON_THROW_ON_ERROR);\n" " if (empty($result)) {\n" " return null;\n" " }\n" @@ -9299,19 +8988,19 @@ static const char* swoole_library_source_core_name_resolver_consul = " public function join(string $name, string $ip, int $port, array $options = []): bool\n" " {\n" " $weight = $options['weight'] ?? 100;\n" - " $data = [\n" - " 'ID' => $this->getServiceId($name, $ip, $port),\n" - " 'Name' => $this->prefix . $name,\n" - " 'Address' => $ip,\n" - " 'Port' => $port,\n" + " $data = [\n" + " 'ID' => $this->getServiceId($name, $ip, $port),\n" + " 'Name' => $this->prefix . $name,\n" + " 'Address' => $ip,\n" + " 'Port' => $port,\n" " 'EnableTagOverride' => false,\n" - " 'Weights' => [\n" + " 'Weights' => [\n" " 'Passing' => $weight,\n" " 'Warning' => 1,\n" " ],\n" " ];\n" " $url = $this->baseUrl . '/v1/agent/service/register';\n" - " $r = request($url, 'PUT', json_encode($data));\n" + " $r = request($url, 'PUT', json_encode($data, JSON_THROW_ON_ERROR));\n" " return $this->checkResponse($r, $url);\n" " }\n" "\n" @@ -9340,11 +9029,11 @@ static const char* swoole_library_source_core_name_resolver_consul = " public function getCluster(string $name): ?Cluster\n" " {\n" " $url = $this->baseUrl . '/v1/catalog/service/' . $this->prefix . $name;\n" - " $r = get($url);\n" + " $r = get($url);\n" " if (!$this->checkResponse($r, $url)) {\n" " return null;\n" " }\n" - " $list = json_decode($r->getBody());\n" + " $list = json_decode($r->getBody(), null, 512, JSON_THROW_ON_ERROR);\n" " if (empty($list)) {\n" " return null;\n" " }\n" @@ -9379,7 +9068,7 @@ static const char* swoole_library_source_core_coroutine_functions = "\n" "function run(callable $fn, ...$args)\n" "{\n" - " $s = new Scheduler();\n" + " $s = new Scheduler();\n" " $options = Coroutine::getOptions();\n" " if (!isset($options['hook_flags'])) {\n" " $s->set(['hook_flags' => SWOOLE_HOOK_ALL]);\n" @@ -9415,7 +9104,7 @@ static const char* swoole_library_source_core_coroutine_functions = "function parallel(int $n, callable $fn): void\n" "{\n" " $count = $n;\n" - " $wg = new WaitGroup($n);\n" + " $wg = new WaitGroup($n);\n" " while ($count--) {\n" " Coroutine::create(function () use ($fn, $wg) {\n" " $fn();\n" @@ -9425,13 +9114,27 @@ static const char* swoole_library_source_core_coroutine_functions = " $wg->wait();\n" "}\n" "\n" + "/**\n" + " * Applies the callback to the elements of the given list.\n" + " *\n" + " * The callback function takes on two parameters. The list parameter's value being the first, and the key/index second.\n" + " * Each callback runs in a new coroutine, allowing the list to be processed in parallel.\n" + " *\n" + " * @param array $list A list of key/value paired input data.\n" + " * @param callable $fn The callback function to apply to each item on the list. The callback takes on two parameters.\n" + " * The list parameter's value being the first, and the key/index second.\n" + " * @param float $timeout > 0 means waiting for the specified number of seconds. other means no waiting.\n" + " * @return array Returns an array containing the results of applying the callback function to the corresponding value\n" + " * and key of the list (used as arguments for the callback). The returned array will preserve the keys of\n" + " * the list.\n" + " */\n" "function map(array $list, callable $fn, float $timeout = -1): array\n" "{\n" " $wg = new WaitGroup(count($list));\n" " foreach ($list as $id => $elem) {\n" " Coroutine::create(function () use ($wg, &$list, $id, $elem, $fn): void {\n" " $list[$id] = null;\n" - " $list[$id] = $fn($elem);\n" + " $list[$id] = $fn($elem, $id);\n" " $wg->done();\n" " });\n" " }\n" @@ -9442,7 +9145,7 @@ static const char* swoole_library_source_core_coroutine_functions = "function deadlock_check()\n" "{\n" " $all_coroutines = Coroutine::listCoroutines();\n" - " $count = Coroutine::stats()['coroutine_num'];\n" + " $count = Coroutine::stats()['coroutine_num'];\n" " echo \"\\n===================================================================\",\n" " \"\\n [FATAL ERROR]: all coroutines (count: {$count}) are asleep - deadlock!\",\n" " \"\\n===================================================================\\n\";\n" @@ -9509,36 +9212,22 @@ static const char* swoole_library_source_ext_curl = "{\n" " $info = $obj->getInfo();\n" " if (is_array($info) and $opt) {\n" - " switch ($opt) {\n" - " case CURLINFO_EFFECTIVE_URL:\n" - " return $info['url'];\n" - " case CURLINFO_HTTP_CODE:\n" - " return $info['http_code'];\n" - " case CURLINFO_CONTENT_TYPE:\n" - " return $info['content_type'];\n" - " case CURLINFO_REDIRECT_COUNT:\n" - " return $info['redirect_count'];\n" - " case CURLINFO_REDIRECT_URL:\n" - " return $info['redirect_url'];\n" - " case CURLINFO_TOTAL_TIME:\n" - " return $info['total_time'];\n" - " case CURLINFO_STARTTRANSFER_TIME:\n" - " return $info['starttransfer_time'];\n" - " case CURLINFO_SIZE_DOWNLOAD:\n" - " return $info['size_download'];\n" - " case CURLINFO_SPEED_DOWNLOAD:\n" - " return $info['speed_download'];\n" - " case CURLINFO_REDIRECT_TIME:\n" - " return $info['redirect_time'];\n" - " case CURLINFO_HEADER_SIZE:\n" - " return $info['header_size'];\n" - " case CURLINFO_PRIMARY_IP:\n" - " return $info['primary_ip'];\n" - " case CURLINFO_PRIVATE:\n" - " return $info['private'];\n" - " default:\n" - " return null;\n" - " }\n" + " return match ($opt) {\n" + " CURLINFO_EFFECTIVE_URL => $info['url'],\n" + " CURLINFO_HTTP_CODE => $info['http_code'],\n" + " CURLINFO_CONTENT_TYPE => $info['content_type'],\n" + " CURLINFO_REDIRECT_COUNT => $info['redirect_count'],\n" + " CURLINFO_REDIRECT_URL => $info['redirect_url'],\n" + " CURLINFO_TOTAL_TIME => $info['total_time'],\n" + " CURLINFO_STARTTRANSFER_TIME => $info['starttransfer_time'],\n" + " CURLINFO_SIZE_DOWNLOAD => $info['size_download'],\n" + " CURLINFO_SPEED_DOWNLOAD => $info['speed_download'],\n" + " CURLINFO_REDIRECT_TIME => $info['redirect_time'],\n" + " CURLINFO_HEADER_SIZE => $info['header_size'],\n" + " CURLINFO_PRIMARY_IP => $info['primary_ip'],\n" + " CURLINFO_PRIVATE => $info['private'],\n" + " default => null,\n" + " };\n" " }\n" " return $info;\n" "}\n" @@ -9761,7 +9450,7 @@ static const char* swoole_library_source_ext_sockets = " $socket->close();\n" "}\n" "\n" - "function swoole_socket_clear_error(Socket $socket = null)\n" + "function swoole_socket_clear_error(?Socket $socket = null)\n" "{\n" " if ($socket) {\n" " $socket->errCode = 0;\n" @@ -9769,7 +9458,7 @@ static const char* swoole_library_source_ext_sockets = " swoole_clear_error();\n" "}\n" "\n" - "function swoole_socket_last_error(Socket $socket = null): int\n" + "function swoole_socket_last_error(?Socket $socket = null): int\n" "{\n" " if ($socket) {\n" " return $socket->errCode;\n" @@ -9798,7 +9487,7 @@ static const char* swoole_library_source_ext_sockets = " return true;\n" " }\n" " $socket->__ext_sockets_nonblock = true;\n" - " $socket->__ext_sockets_timeout = $socket->getOption(SOL_SOCKET, SO_RCVTIMEO);\n" + " $socket->__ext_sockets_timeout = $socket->getOption(SOL_SOCKET, SO_RCVTIMEO);\n" " $socket->setOption(SOL_SOCKET, SO_RCVTIMEO, ['sec' => 0, 'usec' => 1000]);\n" " return true;\n" "}\n" @@ -9838,7 +9527,7 @@ static const char* swoole_library_source_functions = " throw new RuntimeException('require PHP version 7.2 or later');\n" "}\n" "\n" - "if (SWOOLE_USE_SHORTNAME) {\n" + "if (SWOOLE_USE_SHORTNAME) { // @phpstan-ignore if.alwaysTrue\n" " function _string(string $string = ''): Swoole\\StringObject\n" " {\n" " return new Swoole\\StringObject($string);\n" @@ -9857,25 +9546,31 @@ static const char* swoole_library_source_functions = "\n" "class SwooleLibrary\n" "{\n" - " public static $options = [];\n" + " /**\n" + " * @var array\n" + " */\n" + " public static array $options = [];\n" "}\n" "\n" - "function swoole_library_set_options(array $options)\n" + "/**\n" + " * @param array $options\n" + " */\n" + "function swoole_library_set_options(array $options): void\n" "{\n" " SwooleLibrary::$options = $options;\n" "}\n" "\n" - "function swoole_library_get_options()\n" + "function swoole_library_get_options(): array\n" "{\n" " return SwooleLibrary::$options;\n" "}\n" "\n" - "function swoole_library_set_option(string $key, $value)\n" + "function swoole_library_set_option(string $key, mixed $value): void\n" "{\n" " SwooleLibrary::$options[$key] = $value;\n" "}\n" "\n" - "function swoole_library_get_option(string $key)\n" + "function swoole_library_get_option(string $key): mixed\n" "{\n" " return SwooleLibrary::$options[$key] ?? null;\n" "}\n" @@ -9902,7 +9597,7 @@ static const char* swoole_library_source_functions = " $table = new Swoole\\Table($size, 0.25);\n" "\n" " foreach ($_fields as $f) {\n" - " $_f = swoole_string($f)->trim()->split(':');\n" + " $_f = swoole_string($f)->trim()->split(':');\n" " $name = $_f->get(0)->trim()->toString();\n" " $type = $_f->get(1)->trim();\n" "\n" @@ -9928,7 +9623,6 @@ static const char* swoole_library_source_functions = " break;\n" " default:\n" " throw new RuntimeException(\"unknown field type[{$type}]\");\n" - " break;\n" " }\n" " }\n" "\n" @@ -9967,15 +9661,15 @@ static const char* swoole_library_source_functions = " // cgroup v2\n" " $cpu_max = '/sys/fs/cgroup/cpu.max';\n" " if (file_exists($cpu_max)) {\n" - " $cpu_max = file_get_contents($cpu_max);\n" - " $fields = explode($cpu_max, ' ');\n" + " $cpu_max = file_get_contents($cpu_max);\n" + " $fields = explode($cpu_max, ' ');\n" " $quota_us = $fields[0];\n" " if ($quota_us == 'max') {\n" " return swoole_cpu_num();\n" " }\n" " $period_us = $fields[1] ?? 100000;\n" " } else {\n" - " $quota_us = file_get_contents('/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us');\n" + " $quota_us = file_get_contents('/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us');\n" " $period_us = file_get_contents('/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_period_us');\n" " }\n" " $cpu_num = floatval($quota_us) / floatval($period_us);\n" @@ -9983,26 +9677,6 @@ static const char* swoole_library_source_functions = " return swoole_cpu_num();\n" " }\n" " return intval(floor($cpu_num));\n" - "}\n" - "\n" - "if (!function_exists('array_key_last')) {\n" - " function array_key_last(array $array)\n" - " {\n" - " if (!empty($array)) {\n" - " return key(array_slice($array, -1, 1, true));\n" - " }\n" - " return null;\n" - " }\n" - "}\n" - "\n" - "if (!function_exists('array_key_first')) {\n" - " function array_key_first(array $array)\n" - " {\n" - " foreach ($array as $key => $unused) {\n" - " return $key;\n" - " }\n" - " return null;\n" - " }\n" "}\n"; static const char* swoole_library_source_alias = @@ -10017,7 +9691,7 @@ static const char* swoole_library_source_alias = "\n" "declare(strict_types=1);\n" "\n" - "if (SWOOLE_USE_SHORTNAME) {\n" + "if (SWOOLE_USE_SHORTNAME) { // @phpstan-ignore if.alwaysTrue\n" " class_alias(Swoole\\Coroutine\\WaitGroup::class, Co\\WaitGroup::class, true);\n" " class_alias(Swoole\\Coroutine\\Server::class, Co\\Server::class, true);\n" " class_alias(Swoole\\Coroutine\\Server\\Connection::class, Co\\Server\\Connection::class, true);\n" @@ -10044,7 +9718,7 @@ static const char* swoole_library_source_alias_ns = "\n" "use Swoole\\Coroutine;\n" "\n" - "if (SWOOLE_USE_SHORTNAME) {\n" + "if (SWOOLE_USE_SHORTNAME) { // @phpstan-ignore if.alwaysTrue\n" " function run(callable $fn, ...$args)\n" " {\n" " return \\Swoole\\Coroutine\\run($fn, ...$args);\n" @@ -10078,13 +9752,13 @@ void php_swoole_load_library() _eval(swoole_library_source_core_coroutine_http_client_proxy, "@swoole/library/core/Coroutine/Http/ClientProxy.php"); _eval(swoole_library_source_core_coroutine_http_functions, "@swoole/library/core/Coroutine/Http/functions.php"); _eval(swoole_library_source_core_connection_pool, "@swoole/library/core/ConnectionPool.php"); - _eval(swoole_library_source_core_database_object_proxy, "@swoole/library/core/Database/ObjectProxy.php"); + _eval(swoole_library_source_core_database_detects_lost_connections, "@swoole/library/core/Database/DetectsLostConnections.php"); _eval(swoole_library_source_core_database_mysqli_config, "@swoole/library/core/Database/MysqliConfig.php"); _eval(swoole_library_source_core_database_mysqli_exception, "@swoole/library/core/Database/MysqliException.php"); _eval(swoole_library_source_core_database_mysqli_pool, "@swoole/library/core/Database/MysqliPool.php"); _eval(swoole_library_source_core_database_mysqli_proxy, "@swoole/library/core/Database/MysqliProxy.php"); _eval(swoole_library_source_core_database_mysqli_statement_proxy, "@swoole/library/core/Database/MysqliStatementProxy.php"); - _eval(swoole_library_source_core_database_detects_lost_connections, "@swoole/library/core/Database/DetectsLostConnections.php"); + _eval(swoole_library_source_core_database_object_proxy, "@swoole/library/core/Database/ObjectProxy.php"); _eval(swoole_library_source_core_database_pdo_config, "@swoole/library/core/Database/PDOConfig.php"); _eval(swoole_library_source_core_database_pdo_pool, "@swoole/library/core/Database/PDOPool.php"); _eval(swoole_library_source_core_database_pdo_proxy, "@swoole/library/core/Database/PDOProxy.php"); From 7b8e35f114efc335c8faf75d4afbbf7e36b0287f Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Tue, 26 Dec 2023 00:19:10 -0800 Subject: [PATCH 2/4] manually adjust order of loaded classes from Swoole Library --- ext-src/php_swoole_library.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext-src/php_swoole_library.h b/ext-src/php_swoole_library.h index 7afaf25c74d..6d055cf393c 100644 --- a/ext-src/php_swoole_library.h +++ b/ext-src/php_swoole_library.h @@ -9752,13 +9752,13 @@ void php_swoole_load_library() _eval(swoole_library_source_core_coroutine_http_client_proxy, "@swoole/library/core/Coroutine/Http/ClientProxy.php"); _eval(swoole_library_source_core_coroutine_http_functions, "@swoole/library/core/Coroutine/Http/functions.php"); _eval(swoole_library_source_core_connection_pool, "@swoole/library/core/ConnectionPool.php"); - _eval(swoole_library_source_core_database_detects_lost_connections, "@swoole/library/core/Database/DetectsLostConnections.php"); + _eval(swoole_library_source_core_database_object_proxy, "@swoole/library/core/Database/ObjectProxy.php"); _eval(swoole_library_source_core_database_mysqli_config, "@swoole/library/core/Database/MysqliConfig.php"); _eval(swoole_library_source_core_database_mysqli_exception, "@swoole/library/core/Database/MysqliException.php"); _eval(swoole_library_source_core_database_mysqli_pool, "@swoole/library/core/Database/MysqliPool.php"); _eval(swoole_library_source_core_database_mysqli_proxy, "@swoole/library/core/Database/MysqliProxy.php"); _eval(swoole_library_source_core_database_mysqli_statement_proxy, "@swoole/library/core/Database/MysqliStatementProxy.php"); - _eval(swoole_library_source_core_database_object_proxy, "@swoole/library/core/Database/ObjectProxy.php"); + _eval(swoole_library_source_core_database_detects_lost_connections, "@swoole/library/core/Database/DetectsLostConnections.php"); _eval(swoole_library_source_core_database_pdo_config, "@swoole/library/core/Database/PDOConfig.php"); _eval(swoole_library_source_core_database_pdo_pool, "@swoole/library/core/Database/PDOPool.php"); _eval(swoole_library_source_core_database_pdo_proxy, "@swoole/library/core/Database/PDOProxy.php"); From 6a5eb9db05d0ac1cedfc2002a4e4b5de0beb3b7b Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Tue, 26 Dec 2023 23:51:32 -0800 Subject: [PATCH 3/4] update Swoole Library to latest using commit swoole/library@4a621c9a from the master branch --- ext-src/php_swoole_library.h | 349 +++++++++++++++-------------------- 1 file changed, 150 insertions(+), 199 deletions(-) diff --git a/ext-src/php_swoole_library.h b/ext-src/php_swoole_library.h index 6d055cf393c..36569f6b8b4 100644 --- a/ext-src/php_swoole_library.h +++ b/ext-src/php_swoole_library.h @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: 0ecf1907ff52f1b37c06a13898c816b59a6c1ac2 */ +/* $Id: 4a621c9aee49c1bb2ce7653831e87164738eb62a */ #ifndef SWOOLE_LIBRARY_H #define SWOOLE_LIBRARY_H @@ -1526,11 +1526,8 @@ static const char* swoole_library_source_core_object_proxy = " /** @var object */\n" " protected $__object;\n" "\n" - " public function __construct($object)\n" + " public function __construct(object $object)\n" " {\n" - " if (!is_object($object)) {\n" - " throw new \\TypeError('Non-object given');\n" - " }\n" " $this->__object = $object;\n" " }\n" "\n" @@ -2269,7 +2266,7 @@ static const char* swoole_library_source_core_connection_pool = " }\n" "}\n"; -static const char* swoole_library_source_core_database_detects_lost_connections = +static const char* swoole_library_source_core_database_object_proxy = "\n" "/**\n" " * This file is part of Swoole.\n" @@ -2283,70 +2280,11 @@ static const char* swoole_library_source_core_database_detects_lost_connections "\n" "namespace Swoole\\Database;\n" "\n" - "class DetectsLostConnections\n" + "class ObjectProxy extends \\Swoole\\ObjectProxy\n" "{\n" - " private const ERROR_MESSAGES = [\n" - " 'server has gone away',\n" - " 'no connection to the server',\n" - " 'Lost connection',\n" - " 'is dead or not enabled',\n" - " 'Error while sending',\n" - " 'decryption failed or bad record mac',\n" - " 'server closed the connection unexpectedly',\n" - " 'SSL connection has been closed unexpectedly',\n" - " 'Error writing data to the connection',\n" - " 'Resource deadlock avoided',\n" - " 'Transaction() on null',\n" - " 'child connection forced to terminate due to client_idle_limit',\n" - " 'query_wait_timeout',\n" - " 'reset by peer',\n" - " 'Physical connection is not usable',\n" - " 'TCP Provider: Error code 0x68',\n" - " 'ORA-03113',\n" - " 'ORA-03114',\n" - " 'Packets out of order. Expected',\n" - " 'Adaptive Server connection failed',\n" - " 'Communication link failure',\n" - " 'connection is no longer usable',\n" - " 'Login timeout expired',\n" - " 'SQLSTATE[HY000] [2002] Connection refused',\n" - " 'running with the --read-only option so it cannot execute this statement',\n" - " 'The connection is broken and recovery is not possible. The connection is marked by the client driver as unrecoverable. No attempt was made to restore the connection.',\n" - " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again',\n" - " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known',\n" - " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for',\n" - " 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: EOF detected',\n" - " 'SQLSTATE[HY000] [2002] Connection timed out',\n" - " 'SSL: Connection timed out',\n" - " 'SQLSTATE[HY000]: General error: 1105 The last transaction was aborted due to Seamless Scaling. Please retry.',\n" - " 'Temporary failure in name resolution',\n" - " 'SSL: Broken pipe',\n" - " 'SQLSTATE[08S01]: Communication link failure',\n" - " 'SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host',\n" - " 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: No route to host',\n" - " 'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.',\n" - " 'SQLSTATE[08006] [7] could not translate host name',\n" - " 'TCP Provider: Error code 0x274C',\n" - " 'SQLSTATE[HY000] [2002] No such file or directory',\n" - " 'SSL: Operation timed out',\n" - " 'Reason: Server is in script upgrade mode. Only administrator can connect at this time.',\n" - " 'Unknown $curl_error_code: 77',\n" - " 'SSL: Handshake timed out',\n" - " 'SQLSTATE[08006] [7] SSL error: sslv3 alert unexpected message',\n" - " 'SQLSTATE[08006] [7] unrecognized SSL error code:',\n" - " 'SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it',\n" - " ];\n" - "\n" - " public static function causedByLostConnection(\\Throwable $e): bool\n" + " final public function __clone(): void\n" " {\n" - " $message = $e->getMessage();\n" - " foreach (self::ERROR_MESSAGES as $needle) {\n" - " if ($needle !== '' && mb_strpos($message, $needle) !== false) {\n" - " return true;\n" - " }\n" - " }\n" - "\n" - " return false;\n" + " throw new \\Error('Trying to clone an uncloneable database proxy object');\n" " }\n" "}\n"; @@ -2366,36 +2304,28 @@ static const char* swoole_library_source_core_database_mysqli_config = "\n" "class MysqliConfig\n" "{\n" - " /** @var string */\n" - " protected $host = '127.0.0.1';\n" + " protected string $host = '127.0.0.1';\n" "\n" - " /** @var int */\n" - " protected $port = 3306;\n" + " protected int $port = 3306;\n" "\n" - " /** @var string|null */\n" - " protected $unixSocket = '';\n" + " protected ?string $unixSocket;\n" "\n" - " /** @var string */\n" - " protected $dbname = 'test';\n" + " protected string $dbname = 'test';\n" "\n" - " /** @var string */\n" - " protected $charset = 'utf8mb4';\n" + " protected string $charset = 'utf8mb4';\n" "\n" - " /** @var string */\n" - " protected $username = 'root';\n" + " protected string $username = 'root';\n" "\n" - " /** @var string */\n" - " protected $password = 'root';\n" + " protected string $password = 'root';\n" "\n" - " /** @var array */\n" - " protected $options = [];\n" + " protected array $options = [];\n" "\n" " public function getHost(): string\n" " {\n" " return $this->host;\n" " }\n" "\n" - " public function withHost($host): self\n" + " public function withHost(string $host): self\n" " {\n" " $this->host = $host;\n" " return $this;\n" @@ -2406,9 +2336,9 @@ static const char* swoole_library_source_core_database_mysqli_config = " return $this->port;\n" " }\n" "\n" - " public function getUnixSocket(): string\n" + " public function getUnixSocket(): ?string\n" " {\n" - " return $this->unixSocket;\n" + " return $this->unixSocket ?? null;\n" " }\n" "\n" " public function withUnixSocket(?string $unixSocket): self\n" @@ -2558,6 +2488,9 @@ static const char* swoole_library_source_core_database_mysqli_proxy = "\n" "namespace Swoole\\Database;\n" "\n" + "/**\n" + " * @method \\mysqli __getObject()\n" + " */\n" "class MysqliProxy extends ObjectProxy\n" "{\n" " public const IO_METHOD_REGEX = '/^autocommit|begin_transaction|change_user|close|commit|kill|multi_query|ping|prepare|query|real_connect|real_query|reap_async_query|refresh|release_savepoint|rollback|savepoint|select_db|send_query|set_charset|ssl_set$/i';\n" @@ -2571,20 +2504,16 @@ static const char* swoole_library_source_core_database_mysqli_proxy = " /** @var \\mysqli */\n" " protected $__object;\n" "\n" - " /** @var string */\n" - " protected $charsetContext;\n" + " protected string $charsetContext;\n" "\n" - " /** @var array|null */\n" - " protected $setOptContext;\n" + " protected array $setOptContext = [];\n" "\n" - " /** @var array|null */\n" - " protected $changeUserContext;\n" + " protected array $changeUserContext;\n" "\n" " /** @var callable */\n" " protected $constructor;\n" "\n" - " /** @var int */\n" - " protected $round = 0;\n" + " protected int $round = 0;\n" "\n" " public function __construct(callable $constructor)\n" " {\n" @@ -2630,15 +2559,13 @@ static const char* swoole_library_source_core_database_mysqli_proxy = " parent::__construct($constructor());\n" " $this->round++;\n" " /* restore context */\n" - " if ($this->charsetContext) {\n" + " if (!empty($this->charsetContext)) {\n" " $this->__object->set_charset($this->charsetContext);\n" " }\n" - " if ($this->setOptContext) {\n" - " foreach ($this->setOptContext as $opt => $val) {\n" - " $this->__object->set_opt($opt, $val);\n" - " }\n" + " foreach ($this->setOptContext as $opt => $val) {\n" + " $this->__object->set_opt($opt, $val);\n" " }\n" - " if ($this->changeUserContext) {\n" + " if (!empty($this->changeUserContext)) {\n" " $this->__object->change_user(...$this->changeUserContext);\n" " }\n" " }\n" @@ -2660,7 +2587,7 @@ static const char* swoole_library_source_core_database_mysqli_proxy = " return $this->__object->set_charset($charset);\n" " }\n" "\n" - " public function change_user(string $user, string $password, string $database): bool\n" + " public function change_user(string $user, string $password, ?string $database): bool\n" " {\n" " $this->changeUserContext = [$user, $password, $database];\n" " return $this->__object->change_user($user, $password, $database);\n" @@ -2688,23 +2615,17 @@ static const char* swoole_library_source_core_database_mysqli_statement_proxy = " /** @var \\mysqli_stmt */\n" " protected $__object;\n" "\n" - " /** @var string|null */\n" - " protected $queryString;\n" + " protected ?string $queryString;\n" "\n" - " /** @var array|null */\n" - " protected $attrSetContext;\n" + " protected array $attrSetContext = [];\n" "\n" - " /** @var array|null */\n" - " protected $bindParamContext;\n" + " protected array $bindParamContext;\n" "\n" - " /** @var array|null */\n" - " protected $bindResultContext;\n" + " protected array $bindResultContext;\n" "\n" - " /** @var \\Mysqli|MysqliProxy */\n" - " protected $parent;\n" + " protected MysqliProxy $parent;\n" "\n" - " /** @var int */\n" - " protected $parentRound;\n" + " protected int $parentRound;\n" "\n" " public function __construct(\\mysqli_stmt $object, ?string $queryString, MysqliProxy $parent)\n" " {\n" @@ -2736,16 +2657,14 @@ static const char* swoole_library_source_core_database_mysqli_statement_proxy = " if ($this->__object === false) {\n" " throw new MysqliException($parent->error, $parent->errno);\n" " }\n" - " if ($this->bindParamContext) {\n" + " if (!empty($this->bindParamContext)) {\n" " $this->__object->bind_param($this->bindParamContext[0], ...$this->bindParamContext[1]);\n" " }\n" - " if ($this->bindResultContext) {\n" + " if (!empty($this->bindResultContext)) {\n" " $this->__object->bind_result($this->bindResultContext);\n" " }\n" - " if ($this->attrSetContext) {\n" - " foreach ($this->attrSetContext as $attr => $value) {\n" - " $this->__object->attr_set($attr, $value);\n" - " }\n" + " foreach ($this->attrSetContext as $attr => $value) {\n" + " $this->__object->attr_set($attr, $value);\n" " }\n" " continue;\n" " }\n" @@ -2777,7 +2696,7 @@ static const char* swoole_library_source_core_database_mysqli_statement_proxy = " }\n" "}\n"; -static const char* swoole_library_source_core_database_object_proxy = +static const char* swoole_library_source_core_database_detects_lost_connections = "\n" "/**\n" " * This file is part of Swoole.\n" @@ -2791,11 +2710,73 @@ static const char* swoole_library_source_core_database_object_proxy = "\n" "namespace Swoole\\Database;\n" "\n" - "class ObjectProxy extends \\Swoole\\ObjectProxy\n" + "class DetectsLostConnections\n" "{\n" - " final public function __clone(): void\n" + " /**\n" + " * @var array\n" + " */\n" + " private const ERROR_MESSAGES = [\n" + " 'server has gone away',\n" + " 'no connection to the server',\n" + " 'Lost connection',\n" + " 'is dead or not enabled',\n" + " 'Error while sending',\n" + " 'decryption failed or bad record mac',\n" + " 'server closed the connection unexpectedly',\n" + " 'SSL connection has been closed unexpectedly',\n" + " 'Error writing data to the connection',\n" + " 'Resource deadlock avoided',\n" + " 'Transaction() on null',\n" + " 'child connection forced to terminate due to client_idle_limit',\n" + " 'query_wait_timeout',\n" + " 'reset by peer',\n" + " 'Physical connection is not usable',\n" + " 'TCP Provider: Error code 0x68',\n" + " 'ORA-03113',\n" + " 'ORA-03114',\n" + " 'Packets out of order. Expected',\n" + " 'Adaptive Server connection failed',\n" + " 'Communication link failure',\n" + " 'connection is no longer usable',\n" + " 'Login timeout expired',\n" + " 'SQLSTATE[HY000] [2002] Connection refused',\n" + " 'running with the --read-only option so it cannot execute this statement',\n" + " 'The connection is broken and recovery is not possible. The connection is marked by the client driver as unrecoverable. No attempt was made to restore the connection.',\n" + " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again',\n" + " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known',\n" + " 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for',\n" + " 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: EOF detected',\n" + " 'SQLSTATE[HY000] [2002] Connection timed out',\n" + " 'SSL: Connection timed out',\n" + " 'SQLSTATE[HY000]: General error: 1105 The last transaction was aborted due to Seamless Scaling. Please retry.',\n" + " 'Temporary failure in name resolution',\n" + " 'SSL: Broken pipe',\n" + " 'SQLSTATE[08S01]: Communication link failure',\n" + " 'SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host',\n" + " 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: No route to host',\n" + " 'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.',\n" + " 'SQLSTATE[08006] [7] could not translate host name',\n" + " 'TCP Provider: Error code 0x274C',\n" + " 'SQLSTATE[HY000] [2002] No such file or directory',\n" + " 'SSL: Operation timed out',\n" + " 'Reason: Server is in script upgrade mode. Only administrator can connect at this time.',\n" + " 'Unknown $curl_error_code: 77',\n" + " 'SSL: Handshake timed out',\n" + " 'SQLSTATE[08006] [7] SSL error: sslv3 alert unexpected message',\n" + " 'SQLSTATE[08006] [7] unrecognized SSL error code:',\n" + " 'SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it',\n" + " ];\n" + "\n" + " public static function causedByLostConnection(\\Throwable $e): bool\n" " {\n" - " throw new \\Error('Trying to clone an uncloneable database proxy object');\n" + " $message = $e->getMessage();\n" + " foreach (self::ERROR_MESSAGES as $needle) {\n" + " if (mb_strpos($message, $needle) !== false) {\n" + " return true;\n" + " }\n" + " }\n" + "\n" + " return false;\n" " }\n" "}\n"; @@ -2817,31 +2798,23 @@ static const char* swoole_library_source_core_database_pdo_config = "{\n" " public const DRIVER_MYSQL = 'mysql';\n" "\n" - " /** @var string */\n" - " protected $driver = self::DRIVER_MYSQL;\n" + " protected string $driver = self::DRIVER_MYSQL;\n" "\n" - " /** @var string */\n" - " protected $host = '127.0.0.1';\n" + " protected string $host = '127.0.0.1';\n" "\n" - " /** @var int */\n" - " protected $port = 3306;\n" + " protected int $port = 3306;\n" "\n" - " protected string $unixSocket = '';\n" + " protected ?string $unixSocket;\n" "\n" - " /** @var string */\n" - " protected $dbname = 'test';\n" + " protected string $dbname = 'test';\n" "\n" - " /** @var string */\n" - " protected $charset = 'utf8mb4';\n" + " protected string $charset = 'utf8mb4';\n" "\n" - " /** @var string */\n" - " protected $username = 'root';\n" + " protected string $username = 'root';\n" "\n" - " /** @var string */\n" - " protected $password = 'root';\n" + " protected string $password = 'root';\n" "\n" - " /** @var array */\n" - " protected $options = [];\n" + " protected array $options = [];\n" "\n" " public function getDriver(): string\n" " {\n" @@ -2859,7 +2832,7 @@ static const char* swoole_library_source_core_database_pdo_config = " return $this->host;\n" " }\n" "\n" - " public function withHost($host): self\n" + " public function withHost(string $host): self\n" " {\n" " $this->host = $host;\n" " return $this;\n" @@ -2875,9 +2848,9 @@ static const char* swoole_library_source_core_database_pdo_config = " return !empty($this->unixSocket);\n" " }\n" "\n" - " public function getUnixSocket(): string\n" + " public function getUnixSocket(): ?string\n" " {\n" - " return $this->unixSocket;\n" + " return $this->unixSocket ?? null;\n" " }\n" "\n" " public function withUnixSocket(?string $unixSocket): self\n" @@ -2952,7 +2925,7 @@ static const char* swoole_library_source_core_database_pdo_config = " *\n" " * @return string[]\n" " */\n" - " public static function getAvailableDrivers()\n" + " public static function getAvailableDrivers(): array\n" " {\n" " return [\n" " self::DRIVER_MYSQL,\n" @@ -3046,13 +3019,15 @@ static const char* swoole_library_source_core_database_pdo_proxy = "\n" "namespace Swoole\\Database;\n" "\n" + "/**\n" + " * @method \\PDO __getObject()\n" + " */\n" "class PDOProxy extends ObjectProxy\n" "{\n" " /** @var \\PDO */\n" " protected $__object;\n" "\n" - " /** @var array|null */\n" - " protected $setAttributeContext;\n" + " protected array $setAttributeContext = [];\n" "\n" " /** @var callable */\n" " protected $constructor;\n" @@ -3108,10 +3083,8 @@ static const char* swoole_library_source_core_database_pdo_proxy = " $this->__object->setAttribute(\\PDO::ATTR_ERRMODE, \\PDO::ERRMODE_EXCEPTION);\n" " $this->round++;\n" " /* restore context */\n" - " if ($this->setAttributeContext) {\n" - " foreach ($this->setAttributeContext as $attribute => $value) {\n" - " $this->__object->setAttribute($attribute, $value);\n" - " }\n" + " foreach ($this->setAttributeContext as $attribute => $value) {\n" + " $this->__object->setAttribute($attribute, $value);\n" " }\n" " }\n" "\n" @@ -3151,23 +3124,17 @@ static const char* swoole_library_source_core_database_pdo_statement_proxy = " /** @var \\PDOStatement */\n" " protected $__object;\n" "\n" - " /** @var array|null */\n" - " protected $setAttributeContext;\n" + " protected array $setAttributeContext = [];\n" "\n" - " /** @var array|null */\n" - " protected $setFetchModeContext;\n" + " protected array $setFetchModeContext;\n" "\n" - " /** @var array|null */\n" - " protected $bindParamContext;\n" + " protected array $bindParamContext = [];\n" "\n" - " /** @var array|null */\n" - " protected $bindColumnContext;\n" + " protected array $bindColumnContext = [];\n" "\n" - " /** @var array|null */\n" - " protected $bindValueContext;\n" + " protected array $bindValueContext = [];\n" "\n" - " /** @var \\PDO|PDOProxy */\n" - " protected $parent;\n" + " protected PDOProxy $parent;\n" "\n" " /** @var int */\n" " protected $parentRound;\n" @@ -3192,28 +3159,20 @@ static const char* swoole_library_source_core_database_pdo_statement_proxy = " $parent = $this->parent->__getObject();\n" " $this->__object = $parent->prepare($this->__object->queryString);\n" "\n" - " if ($this->setAttributeContext) {\n" - " foreach ($this->setAttributeContext as $attribute => $value) {\n" - " $this->__object->setAttribute($attribute, $value);\n" - " }\n" + " foreach ($this->setAttributeContext as $attribute => $value) {\n" + " $this->__object->setAttribute($attribute, $value);\n" " }\n" - " if ($this->setFetchModeContext) {\n" + " if (!empty($this->setFetchModeContext)) {\n" " $this->__object->setFetchMode(...$this->setFetchModeContext);\n" " }\n" - " if ($this->bindParamContext) {\n" - " foreach ($this->bindParamContext as $param => $item) {\n" - " $this->__object->bindParam($param, ...$item);\n" - " }\n" + " foreach ($this->bindParamContext as $param => $item) {\n" + " $this->__object->bindParam($param, ...$item);\n" " }\n" - " if ($this->bindColumnContext) {\n" - " foreach ($this->bindColumnContext as $column => $item) {\n" - " $this->__object->bindColumn($column, ...$item);\n" - " }\n" + " foreach ($this->bindColumnContext as $column => $item) {\n" + " $this->__object->bindColumn($column, ...$item);\n" " }\n" - " if ($this->bindValueContext) {\n" - " foreach ($this->bindValueContext as $value => $item) {\n" - " $this->__object->bindParam($value, ...$item);\n" - " }\n" + " foreach ($this->bindValueContext as $value => $item) {\n" + " $this->__object->bindParam($value, ...$item);\n" " }\n" " $ret = $this->__object->{$name}(...$arguments);\n" " } else {\n" @@ -3271,36 +3230,28 @@ static const char* swoole_library_source_core_database_redis_config = "\n" "class RedisConfig\n" "{\n" - " /** @var string */\n" - " protected $host = '127.0.0.1';\n" + " protected string $host = '127.0.0.1';\n" "\n" - " /** @var int */\n" - " protected $port = 6379;\n" + " protected int $port = 6379;\n" "\n" - " /** @var float */\n" - " protected $timeout = 0.0;\n" + " protected float $timeout = 0.0;\n" "\n" - " /** @var string */\n" - " protected $reserved = '';\n" + " protected string $reserved = '';\n" "\n" - " /** @var int */\n" - " protected $retry_interval = 0;\n" + " protected int $retry_interval = 0;\n" "\n" - " /** @var float */\n" - " protected $read_timeout = 0.0;\n" + " protected float $read_timeout = 0.0;\n" "\n" - " /** @var string */\n" - " protected $auth = '';\n" + " protected string $auth = '';\n" "\n" - " /** @var int */\n" - " protected $dbIndex = 0;\n" + " protected int $dbIndex = 0;\n" "\n" - " public function getHost()\n" + " public function getHost(): string\n" " {\n" " return $this->host;\n" " }\n" "\n" - " public function withHost($host): self\n" + " public function withHost(string $host): self\n" " {\n" " $this->host = $host;\n" " return $this;\n" @@ -4032,7 +3983,7 @@ static const char* swoole_library_source_core_curl_handler = " }\n" "\n" " /**\n" - " * @throws Swoole\\Curl\\Exception\n" + " * @throws Exception\n" " */\n" " private function setOption(int $opt, mixed $value): bool\n" " {\n" From e6605a5dbe1cb2deafc2eda97f980a2c6991180d Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Wed, 27 Dec 2023 19:08:49 -0800 Subject: [PATCH 4/4] update Swoole Library to latest * Use commit swoole/library@2ff30e0 from the master branch. * With PR swoole/library#166 included. --- ext-src/php_swoole_library.h | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/ext-src/php_swoole_library.h b/ext-src/php_swoole_library.h index 36569f6b8b4..555abe03ed4 100644 --- a/ext-src/php_swoole_library.h +++ b/ext-src/php_swoole_library.h @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: 4a621c9aee49c1bb2ce7653831e87164738eb62a */ +/* $Id: 2ff30e0a106505dd57c838de88af0254500e7ce5 */ #ifndef SWOOLE_LIBRARY_H #define SWOOLE_LIBRARY_H @@ -3246,6 +3246,11 @@ static const char* swoole_library_source_core_database_redis_config = "\n" " protected int $dbIndex = 0;\n" "\n" + " /**\n" + " * @var array\n" + " */\n" + " protected array $options = [];\n" + "\n" " public function getHost(): string\n" " {\n" " return $this->host;\n" @@ -3333,6 +3338,36 @@ static const char* swoole_library_source_core_database_redis_config = " $this->dbIndex = $dbIndex;\n" " return $this;\n" " }\n" + "\n" + " /**\n" + " * Add a configurable option.\n" + " */\n" + " public function withOption(int $option, mixed $value): self\n" + " {\n" + " $this->options[$option] = $value;\n" + " return $this;\n" + " }\n" + "\n" + " /**\n" + " * Add/override configurable options.\n" + " *\n" + " * @param array $options\n" + " */\n" + " public function setOptions(array $options): self\n" + " {\n" + " $this->options = $options;\n" + " return $this;\n" + " }\n" + "\n" + " /**\n" + " * Get configurable options.\n" + " *\n" + " * @return array\n" + " */\n" + " public function getOptions(): array\n" + " {\n" + " return $this->options;\n" + " }\n" "}\n"; static const char* swoole_library_source_core_database_redis_pool = @@ -3385,6 +3420,12 @@ static const char* swoole_library_source_core_database_redis_pool = " if ($this->config->getDbIndex() !== 0) {\n" " $redis->select($this->config->getDbIndex());\n" " }\n" + "\n" + " /* Set Redis options. */\n" + " foreach ($this->config->getOptions() as $key => $value) {\n" + " $redis->setOption($key, $value);\n" + " }\n" + "\n" " return $redis;\n" " }, $size);\n" " }\n"