Skip to content

Commit 690a195

Browse files
djw1028769140sy-records
authored andcommitted
Update get_function_info
Co-authored-by: djw <1028769140@qq.com> Co-authored-by: sy-records <52o@qq52o.cn> Co-authored-by: dingjiawei <1028769140@qq.com> Co-committed-by: dingjiawei <1028769140@qq.com>
1 parent bec0dfe commit 690a195

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/core/Server/Admin.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -756,23 +756,41 @@ public static function handlerGetClassInfo($server, $msg)
756756
public static function handlerGetFunctionInfo($server, $msg)
757757
{
758758
$json = json_decode($msg, true);
759-
if (!$json || empty($json['function_name'])) {
759+
760+
$class_name = $json['class_name'] ?? '';
761+
$function_name = $json['function_name'] ?? '';
762+
763+
if (!$json || empty($function_name)) {
760764
return self::json('require function_name', 4004);
761765
}
762-
if (!function_exists($json['function_name'])) {
763-
return self::json("{$json['function_name']} not exists", 4004);
766+
767+
$is_static = false;
768+
if (!empty($class_name)) {
769+
if (!class_exists($class_name)) {
770+
return self::json("{$class_name} not exists", 4004);
771+
}
772+
if (!method_exists($class_name, $function_name)) {
773+
return self::json("{$class_name}\\{$function_name} not exists", 4004);
774+
}
775+
$ref = new \ReflectionMethod($class_name, $function_name);
776+
$is_static = $ref->isStatic();
777+
} else {
778+
if (!function_exists($function_name)) {
779+
return self::json("{$function_name} not exists", 4004);
780+
}
781+
$ref = new \ReflectionFunction($function_name);
764782
}
765-
$function = new \ReflectionFunction($json['function_name']);
766783

767784
$result = [
768-
'filename' => $function->getFileName(),
769-
'line' => $function->getStartLine() ?? '',
770-
'num' => $function->getNumberOfParameters(),
771-
'user_defined' => $function->isUserDefined(),
772-
'extension' => $function->getExtensionName(),
785+
'filename' => $ref->getFileName(),
786+
'line' => $ref->getStartLine() ?? '',
787+
'num' => $ref->getNumberOfParameters(),
788+
'user_defined' => $ref->isUserDefined(),
789+
'extension' => $ref->getExtensionName(),
790+
'is_static' => $is_static,
773791
];
774792

775-
$params = $function->getParameters();
793+
$params = $ref->getParameters();
776794

777795
$list = [];
778796
foreach ($params as $param) {

0 commit comments

Comments
 (0)