Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-rpc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-rpc
Commits
fd888caa
Commit
fd888caa
authored
Apr 09, 2020
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改生成权限名规则
parent
a35ed375
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
README.md
README.md
+8
-8
PermAnnotationAspect.php
src/Aspect/PermAnnotationAspect.php
+10
-0
No files found.
README.md
View file @
fd888caa
...
...
@@ -26,30 +26,30 @@ composer require meibuyu/micro @dev
> 权限名会拼接env文件中的APP_NAME属性,请注意唯一性
> 所有权限必须存在于用户服务的权限表中,若不存在,请联系管理员添加权限
##### 1、@AutoPerm
在控制器头部添加@AutoPerm注解,为该控制器下所有的方法添加鉴权功能,生成的权限名为
`
小写控制名_
方法名`
在控制器头部添加@AutoPerm注解,为该控制器下所有的方法添加鉴权功能,生成的权限名为
`
蛇形命名空间_蛇形控制名_蛇形
方法名`
```
/**
* @AutoPerm()
*/
class UserController {}
class User
Info
Controller {}
```
参数:
> 1. prefix, 前缀(字符串),默认为
小写控制器名(user
)
> 1. prefix, 前缀(字符串),默认为
蛇形命名空间_蛇形控制名(user_info
)
> 2. exclude, 要排除的方法名(字符串数组),默认为空
```
/**
* @AutoPerm(prefix="user", exclude={"
index
"})
* @AutoPerm(prefix="user", exclude={"
getUser
"})
*/
class UserController {}
class User
Info
Controller {}
```
##### 2、@Perm
在控制器中的方法头部添加@Perm注解,为当前方法添加鉴权功能,生成权限名为
`
小写控制名_
方法名`
在控制器中的方法头部添加@Perm注解,为当前方法添加鉴权功能,生成权限名为
`
蛇形命名空间_蛇形控制名_蛇形
方法名`
```
/**
* @Perm()
*/
function get
_u
ser {}
function get
U
ser {}
```
参数:
> name, 前缀(字符串),默认为小写控制器名拼接方法名(user),如果填写指定的名称,会覆盖@AutoPerm的prefix和exclude
...
...
@@ -57,6 +57,6 @@ function get_user {}
/**
* @Perm("get_user")
*/
function get
_u
ser {}
function get
U
ser {}
```
src/Aspect/PermAnnotationAspect.php
View file @
fd888caa
...
...
@@ -95,6 +95,7 @@ class PermAnnotationAspect extends AbstractAspect
if
(
$prefix
[
-
1
]
!==
'_'
)
{
$prefix
.=
'_'
;
}
$methodName
=
$this
->
parseMethodName
(
$methodName
);
return
$appName
.
'_'
.
$prefix
.
$methodName
;
}
...
...
@@ -108,6 +109,15 @@ class PermAnnotationAspect extends AbstractAspect
return
$prefix
;
}
// 处理方法名
protected
function
parseMethodName
(
string
$methodName
)
:
string
{
$name
=
Str
::
snake
(
$methodName
);
$name
=
str_replace
(
'__'
,
'_'
,
$name
);
trim
(
$name
,
'_'
);
return
$name
;
}
// 获取注解
public
function
getAnnotations
(
ProceedingJoinPoint
$proceedingJoinPoint
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment