From 9a73f6bb286b70fad6d63bd1702a070827350625 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Tue, 17 Dec 2019 08:58:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=9D=83=E9=99=90=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=96=B9=E6=B3=95=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/logic/PermissionManager.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/logic/PermissionManager.php b/backend/logic/PermissionManager.php index e1a80b0..c6632ad 100644 --- a/backend/logic/PermissionManager.php +++ b/backend/logic/PermissionManager.php @@ -3,6 +3,7 @@ namespace backend\logic; use ReflectionClass; use ReflectionException; +use ReflectionMethod; use yii; class PermissionManager @@ -109,7 +110,7 @@ class PermissionManager $controllerPregRes = preg_match("/(?<=DESCRIBE ).*?(?= DESCRIBE)/", $controllerComment, $controllerDescribe); if ($controllerPregRes) { $permission = self::getActionsInController($controllerObject, $controllerDescribe, $prefix, $permission); - $permission = self::getActionInController($reflection, $prefix, $controllerDescribe, $permission); + $permission = self::getActionInController($className, $prefix, $controllerDescribe, $permission); } return $permission; } @@ -136,16 +137,18 @@ class PermissionManager /** * 获取控制器类中的action方法权限 - * 获取所有的action方法,若注释中存在ACTION标记,则记录 - * @param $controllerObject + * 通过ReflectionClass方法获取所有的action方法,若注释中存在ACTION标记,则记录 + * @param $className * @param $prefix * @param $controllerDescribe * @param array $permission 权限数组 * @return array 权限数组 + * @throws ReflectionException */ - private static function getActionInController($controllerObject, $prefix, $controllerDescribe, $permission = []) + private static function getActionInController($className, $prefix, $controllerDescribe, $permission = []) { - foreach ($controllerObject->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { + $reflection = new ReflectionClass($className); //通过ReflectionClass方法获取该类的所有信息,包括参数方法等 + foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { //action的注释 $actionComment = $method->getDocComment(); $actionPregRes = preg_match("/(?<=ACTION ).*?(?= ACTION)/", $actionComment, $actionDescribe);