From da9f5f4530e8924c0696ed1ff7aeefb375248e62 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Tue, 26 Oct 2021 11:17:52 +0800 Subject: [PATCH 1/2] Optimize namespace --- src/core/Server/Admin.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/Server/Admin.php b/src/core/Server/Admin.php index 950a56fd..7f60438b 100644 --- a/src/core/Server/Admin.php +++ b/src/core/Server/Admin.php @@ -14,6 +14,8 @@ use Reflection; use ReflectionClass; use ReflectionExtension; +use ReflectionFunction; +use ReflectionMethod; use Swoole\Coroutine; use Swoole\Http\Request; use Swoole\Http\Response; @@ -133,10 +135,7 @@ function ($server, $msg) { $server->addCommand( 'server_setting', $accepted_process_types, - function ($server, $msg) { - /** - * @var Server $server - */ + function (Server $server, $msg) { $setting = $server->setting; $setting['mode'] = $server->mode; $setting['host'] = $server->host; @@ -256,7 +255,7 @@ function ($server, $msg) { $extensions = get_loaded_extensions(); $list = []; foreach ($extensions as $key => $extension) { - $ext = new \ReflectionExtension($extension); + $ext = new ReflectionExtension($extension); $list[$key] = [ 'id' => ++$key, 'name' => $extension, @@ -720,7 +719,7 @@ public static function handlerGetClassInfo($server, $msg) foreach ($data as $k => $v) { $name = $v->getName(); $line = $v->getStartLine(); - $modifiers = \Reflection::getModifierNames($v->getModifiers()); + $modifiers = Reflection::getModifierNames($v->getModifiers()); if ($v->isStatic()) { $static[] = [ 'name' => $name, @@ -782,13 +781,13 @@ public static function handlerGetFunctionInfo($server, $msg) if (!method_exists($className, $functionName)) { return self::json("{$className}->{$functionName} not exists", 4004); } - $ref = new \ReflectionMethod($className, $functionName); + $ref = new ReflectionMethod($className, $functionName); $isStatic = $ref->isStatic(); } else { if (!function_exists($functionName)) { return self::json("{$functionName} not exists", 4004); } - $ref = new \ReflectionFunction($functionName); + $ref = new ReflectionFunction($functionName); } $result = [ @@ -921,7 +920,7 @@ public static function handlerGetDefinedFunctions($server, $msg) $arr['internal'] = $functions['internal']; foreach ($functions['user'] as $function_name) { - $function = new \ReflectionFunction($function_name); + $function = new ReflectionFunction($function_name); $filename = $function->getFileName(); $line = $function->getStartLine(); $arr['user'][] = [ From f572744b8e81bf61de7e26374501ac670944e77c Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Wed, 27 Oct 2021 11:39:07 +0800 Subject: [PATCH 2/2] Update get_class_info to be compatible with interface_name --- src/core/Server/Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Server/Admin.php b/src/core/Server/Admin.php index 7f60438b..d59676c8 100644 --- a/src/core/Server/Admin.php +++ b/src/core/Server/Admin.php @@ -643,7 +643,7 @@ public static function handlerGetClassInfo($server, $msg) } if (!empty($json['class_name'])) { - if (!class_exists($json['class_name'], false)) { + if (!class_exists($json['class_name'], false) && !interface_exists($json['class_name'], false)) { return self::json("{$json['class_name']} not exists", 4003); } $name = $json['class_name'];