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
Hide 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 {}
function getUser {}
```
参数:
> name, 前缀(字符串),默认为
小写控制器名拼接方法名(user),如果填写指定的名称,会覆盖@AutoPerm的prefix和exclude
> name, 前缀(字符串),默认为
蛇形方法名(user)
```
/**
* @Perm("get_user")
...
...
src/Aspect/PermAnnotationAspect.php
View file @
4a2d712e
...
...
@@ -67,36 +67,24 @@ class PermAnnotationAspect extends AbstractAspect
/** @var AutoPerm $autoPerm */
/** @var Perm $perm */
[
$autoPerm
,
$perm
]
=
$this
->
getAnnotations
(
$proceedingJoinPoint
);
if
(
$perm
&&
$perm
->
name
)
{
// 如果有指定权限名,直接返回
return
$perm
->
name
;
}
else
{
$methodName
=
$proceedingJoinPoint
->
methodName
;
$className
=
$proceedingJoinPoint
->
className
;
if
(
$autoPerm
)
{
if
(
in_array
(
$methodName
,
$autoPerm
->
exclude
))
{
// 排除不鉴权的方法
return
false
;
}
if
(
$autoPerm
->
prefix
)
{
// 如果有指定前缀,直接拼接返回
return
$this
->
parseName
(
$autoPerm
->
prefix
,
$methodName
);
}
}
return
$this
->
parseName
(
$this
->
genPrefix
(
$className
),
$methodName
);
$className
=
$proceedingJoinPoint
->
className
;
$methodName
=
$proceedingJoinPoint
->
methodName
;
if
(
$autoPerm
&&
in_array
(
$methodName
,
$autoPerm
->
exclude
))
{
return
false
;
// 跳过不需要鉴权的方法
}
$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的唯一性
$appName
=
$this
->
config
->
get
(
'app_name'
);
if
(
$prefix
[
-
1
]
!==
'_'
)
{
$prefix
.=
'_'
;
}
$methodName
=
$this
->
parseMethodName
(
$methodName
);
return
$appName
.
'_'
.
$prefix
.
$methodName
;
$appName
=
trim
(
$this
->
config
->
get
(
'app_name'
),
'_'
);
$prefix
=
trim
(
$prefix
,
'_'
);
$name
=
trim
(
$name
,
'_'
);
return
$appName
.
'_'
.
$prefix
.
'_'
.
$name
;
}
// 生成前缀
...
...
@@ -109,13 +97,12 @@ class PermAnnotationAspect extends AbstractAspect
return
$prefix
;
}
//
处理方法名
protected
function
parseMethod
Name
(
string
$methodName
)
:
string
//
生成名称
protected
function
gen
Name
(
string
$methodName
)
:
string
{
$name
=
Str
::
snake
(
$methodName
);
$name
=
str_replace
(
'__'
,
'_'
,
$name
);
trim
(
$name
,
'_'
);
return
$name
;
$methodName
=
Str
::
snake
(
$methodName
);
$methodName
=
str_replace
(
'__'
,
'_'
,
$methodName
);
return
$methodName
;
}
// 获取注解
...
...
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