From a43a4a429ee544c80c0f25b6b41ff5cc4e089214 Mon Sep 17 00:00:00 2001 From: sunxyw Date: Thu, 7 Apr 2022 19:09:28 +0800 Subject: [PATCH] add reflection util --- src/ZM/Utils/ReflectionUtil.php | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/ZM/Utils/ReflectionUtil.php diff --git a/src/ZM/Utils/ReflectionUtil.php b/src/ZM/Utils/ReflectionUtil.php new file mode 100644 index 00000000..faea361a --- /dev/null +++ b/src/ZM/Utils/ReflectionUtil.php @@ -0,0 +1,43 @@ +getType(); + // 没有声明类型或为基本类型 + if (!$type instanceof ReflectionNamedType || $type->isBuiltin()) { + return null; + } + + // 获取类名 + $class_name = $type->getName(); + + // 如果存在父类 + if (!is_null($class = $parameter->getDeclaringClass())) { + if ($class_name === 'self') { + return $class->getName(); + } + + if ($class_name === 'parent' && $parent = $class->getParentClass()) { + return $parent->getName(); + } + } + + return $class_name; + } +}