Browse Source

refactor:修改权限获取方法匹配规则

antshop
linyaostalker 5 years ago
parent
commit
a36a90c13d
  1. 8
      backend/logic/PermissionManager.php

8
backend/logic/PermissionManager.php

@ -10,8 +10,8 @@ class PermissionManager
{
/**
* 获取app的已做标记控制器的权限
* DESCRIBE 控制器描述,只有控制器的注释添加了该描述,才会自动匹配该控制器;使用例子:DESCRIBE {controllerDescribe} DESCRIBE
* ACTION 方法描述,只有控制器下action方法的注释添加了该描述,才会自动匹配该action方法;使用例子:ACTION {actionDescribe} ACTION
* DESCRIBE 控制器描述,只有控制器的注释添加了该描述,才会自动匹配该控制器;使用例子:@DESCRIBE {controllerDescribe} DESCRIBE
* ACTION 方法描述,只有控制器下action方法的注释添加了该描述,才会自动匹配该action方法;使用例子:@ACTION {actionDescribe} ACTION
* 匹配控制器中actions的方法,需要添加id参数并且在标明含义,例子:
* '{actionName}' => [
* 'class' => 'xxx\xxx\xxx',
@ -107,7 +107,7 @@ class PermissionManager
$prefix = '/'.$controllerObject->id.'/';
$reflection = new ReflectionClass($className); //通过ReflectionClass方法获取该类的所有信息,包括参数方法等
$controllerComment = $reflection->getDocComment();
$controllerPregRes = preg_match("/(?<=DESCRIBE ).*?(?= DESCRIBE)/", $controllerComment, $controllerDescribe);
$controllerPregRes = preg_match("/(?<=@DESCRIBE ).*?(?= DESCRIBE)/", $controllerComment, $controllerDescribe);
if ($controllerPregRes) {
$permission = self::getActionsInController($controllerObject, $controllerDescribe, $prefix, $permission);
$permission = self::getActionInController($className, $prefix, $controllerDescribe, $permission);
@ -151,7 +151,7 @@ class PermissionManager
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
//action的注释
$actionComment = $method->getDocComment();
$actionPregRes = preg_match("/(?<=ACTION ).*?(?= ACTION)/", $actionComment, $actionDescribe);
$actionPregRes = preg_match("/(?<=@ACTION ).*?(?= ACTION)/", $actionComment, $actionDescribe);
if ($actionPregRes) {
$actionName = $method->getName();
if ($actionName != 'actions' && strpos($actionName, 'action') === 0) {

Loading…
Cancel
Save