Skip to content

Commit

Permalink
Update get_function_info
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
djw1028769140 and sy-records committed Oct 22, 2021
1 parent bec0dfe commit 690a195
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/core/Server/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,23 +756,41 @@ public static function handlerGetClassInfo($server, $msg)
public static function handlerGetFunctionInfo($server, $msg)
{
$json = json_decode($msg, true);
if (!$json || empty($json['function_name'])) {

$class_name = $json['class_name'] ?? '';
$function_name = $json['function_name'] ?? '';

if (!$json || empty($function_name)) {
return self::json('require function_name', 4004);
}
if (!function_exists($json['function_name'])) {
return self::json("{$json['function_name']} not exists", 4004);

$is_static = false;
if (!empty($class_name)) {
if (!class_exists($class_name)) {
return self::json("{$class_name} not exists", 4004);
}
if (!method_exists($class_name, $function_name)) {
return self::json("{$class_name}\\{$function_name} not exists", 4004);
}
$ref = new \ReflectionMethod($class_name, $function_name);
$is_static = $ref->isStatic();
} else {
if (!function_exists($function_name)) {
return self::json("{$function_name} not exists", 4004);
}
$ref = new \ReflectionFunction($function_name);
}
$function = new \ReflectionFunction($json['function_name']);

$result = [
'filename' => $function->getFileName(),
'line' => $function->getStartLine() ?? '',
'num' => $function->getNumberOfParameters(),
'user_defined' => $function->isUserDefined(),
'extension' => $function->getExtensionName(),
'filename' => $ref->getFileName(),
'line' => $ref->getStartLine() ?? '',
'num' => $ref->getNumberOfParameters(),
'user_defined' => $ref->isUserDefined(),
'extension' => $ref->getExtensionName(),
'is_static' => $is_static,
];

$params = $function->getParameters();
$params = $ref->getParameters();

$list = [];
foreach ($params as $param) {
Expand Down

0 comments on commit 690a195

Please sign in to comment.