Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-micro
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
1
Merge Requests
1
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-micro
Commits
4a2d712e
Commit
4a2d712e
authored
Apr 10, 2020
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整鉴权注解逻辑
parent
fd888caa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
31 deletions
+18
-31
README.md
README.md
+1
-1
PermAnnotationAspect.php
src/Aspect/PermAnnotationAspect.php
+17
-30
No files found.
README.md
View file @
4a2d712e
...
@@ -52,7 +52,7 @@ class UserInfoController {}
...
@@ -52,7 +52,7 @@ class UserInfoController {}
function getUser {}
function getUser {}
```
```
参数:
参数:
> name, 前缀(字符串),默认为
小写控制器名拼接方法名(user),如果填写指定的名称,会覆盖@AutoPerm的prefix和exclude
> name, 前缀(字符串),默认为
蛇形方法名(user)
```
```
/**
/**
* @Perm("get_user")
* @Perm("get_user")
...
...
src/Aspect/PermAnnotationAspect.php
View file @
4a2d712e
...
@@ -67,36 +67,24 @@ class PermAnnotationAspect extends AbstractAspect
...
@@ -67,36 +67,24 @@ class PermAnnotationAspect extends AbstractAspect
/** @var AutoPerm $autoPerm */
/** @var AutoPerm $autoPerm */
/** @var Perm $perm */
/** @var Perm $perm */
[
$autoPerm
,
$perm
]
=
$this
->
getAnnotations
(
$proceedingJoinPoint
);
[
$autoPerm
,
$perm
]
=
$this
->
getAnnotations
(
$proceedingJoinPoint
);
if
(
$perm
&&
$perm
->
name
)
{
// 如果有指定权限名,直接返回
return
$perm
->
name
;
}
else
{
$methodName
=
$proceedingJoinPoint
->
methodName
;
$className
=
$proceedingJoinPoint
->
className
;
$className
=
$proceedingJoinPoint
->
className
;
if
(
$autoPerm
)
{
$methodName
=
$proceedingJoinPoint
->
methodName
;
if
(
in_array
(
$methodName
,
$autoPerm
->
exclude
))
{
if
(
$autoPerm
&&
in_array
(
$methodName
,
$autoPerm
->
exclude
))
{
// 排除不鉴权的方法
return
false
;
// 跳过不需要鉴权的方法
return
false
;
}
if
(
$autoPerm
->
prefix
)
{
// 如果有指定前缀,直接拼接返回
return
$this
->
parseName
(
$autoPerm
->
prefix
,
$methodName
);
}
}
return
$this
->
parseName
(
$this
->
genPrefix
(
$className
),
$methodName
);
}
}
$prefix
=
$autoPerm
&&
$autoPerm
->
prefix
?
$autoPerm
->
prefix
:
$this
->
genPrefix
(
$className
);
$name
=
$perm
&&
$perm
->
name
?
$perm
->
name
:
$this
->
genName
(
$methodName
);
return
$this
->
parsePermName
(
$prefix
,
$name
);
}
}
// 拼接权限名
// 拼接权限名
protected
function
parse
Name
(
$prefix
,
$methodN
ame
)
protected
function
parse
PermName
(
$prefix
,
$n
ame
)
{
{
// 注意每个应用的app_name的唯一性
// 注意每个应用的app_name的唯一性
$appName
=
$this
->
config
->
get
(
'app_name'
);
$appName
=
trim
(
$this
->
config
->
get
(
'app_name'
),
'_'
);
if
(
$prefix
[
-
1
]
!==
'_'
)
{
$prefix
=
trim
(
$prefix
,
'_'
);
$prefix
.=
'_'
;
$name
=
trim
(
$name
,
'_'
);
}
return
$appName
.
'_'
.
$prefix
.
'_'
.
$name
;
$methodName
=
$this
->
parseMethodName
(
$methodName
);
return
$appName
.
'_'
.
$prefix
.
$methodName
;
}
}
// 生成前缀
// 生成前缀
...
@@ -109,13 +97,12 @@ class PermAnnotationAspect extends AbstractAspect
...
@@ -109,13 +97,12 @@ class PermAnnotationAspect extends AbstractAspect
return
$prefix
;
return
$prefix
;
}
}
//
处理方法名
//
生成名称
protected
function
parseMethod
Name
(
string
$methodName
)
:
string
protected
function
gen
Name
(
string
$methodName
)
:
string
{
{
$name
=
Str
::
snake
(
$methodName
);
$methodName
=
Str
::
snake
(
$methodName
);
$name
=
str_replace
(
'__'
,
'_'
,
$name
);
$methodName
=
str_replace
(
'__'
,
'_'
,
$methodName
);
trim
(
$name
,
'_'
);
return
$methodName
;
return
$name
;
}
}
// 获取注解
// 获取注解
...
...
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