File tree Expand file tree Collapse file tree 3 files changed +16
-7
lines changed Expand file tree Collapse file tree 3 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace TinyAuth \Auth ;
4
4
5
+ use BackedEnum ;
5
6
use Cake \Core \Configure ;
6
7
use Cake \Core \Exception \CakeException ;
8
+ use Cake \Database \Type \EnumLabelInterface ;
7
9
use Cake \Datasource \ResultSetInterface ;
8
10
use Cake \ORM \TableRegistry ;
9
11
use Cake \Utility \Hash ;
@@ -616,6 +618,13 @@ protected function _mapped(array $roles) {
616
618
617
619
$ array = [];
618
620
foreach ($ roles as $ role ) {
621
+ if ($ role instanceof BackedEnum) {
622
+ $ alias = $ role instanceof EnumLabelInterface ? $ role ->label () : $ role ->name ;
623
+ $ array [$ role ->value ] = $ alias ;
624
+
625
+ continue ;
626
+ }
627
+
619
628
$ alias = array_keys ($ availableRoles , $ role );
620
629
$ alias = array_shift ($ alias );
621
630
if (!$ alias || !is_string ($ alias )) {
Original file line number Diff line number Diff line change @@ -475,16 +475,16 @@ protected function _setDefaults(): void {
475
475
* @return bool True if $user is authorized, otherwise false
476
476
*/
477
477
public function isAuthorized ($ user = null , ?ServerRequest $ request = null ): bool {
478
- if (empty ( $ user) && !$ this ->user ()) {
478
+ if (! $ user && !$ this ->user ()) {
479
479
return false ;
480
480
}
481
- if (empty ( $ user) ) {
481
+ if (! $ user ) {
482
482
$ user = $ this ->user ();
483
483
}
484
- if (empty ( $ request) ) {
484
+ if (! $ request ) {
485
485
$ request = $ this ->getController ()->getRequest ();
486
486
}
487
- if (empty ( $ this ->_authorizeObjects ) ) {
487
+ if (! $ this ->_authorizeObjects ) {
488
488
$ this ->constructAuthorize ();
489
489
}
490
490
foreach ($ this ->_authorizeObjects as $ authorizer ) {
Original file line number Diff line number Diff line change @@ -86,11 +86,11 @@ public function shutdown(EventInterface $event): void {
86
86
$ access = [];
87
87
foreach ($ availableRoles as $ role => $ id ) {
88
88
if ($ user ) {
89
- $ user = $ this ->_injectRole ($ user , $ role , $ id );
89
+ $ tmpUser = $ this ->_injectRole ($ user , $ role , $ id );
90
90
} else {
91
- $ user = $ this ->_generateUser ($ role , $ id );
91
+ $ tmpUser = $ this ->_generateUser ($ role , $ id );
92
92
}
93
- $ access [$ role ] = $ this ->_checkUser ($ user , $ params );
93
+ $ access [$ role ] = $ this ->_checkUser ($ tmpUser , $ params );
94
94
}
95
95
$ data ['access ' ] = $ access ;
96
96
You can’t perform that action at this time.
0 commit comments