|
|
@ -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); |
|
|
|