Skip to content

Commit 60a0dc6

Browse files
committed
Fix up role reading for BackedEnums
1 parent 87df541 commit 60a0dc6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Auth/AclTrait.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected function _isProtectedPrefix($prefix, array $protectedPrefixes) {
144144
}
145145

146146
/**
147-
* @param array<int> $userRoles
147+
* @param array<string, int|string> $userRoles
148148
* @param array $params
149149
*
150150
* @return bool
@@ -259,7 +259,7 @@ protected function _prefixesFromRoles(array $roles) {
259259
/**
260260
* @param string $prefix
261261
* @param array<string> $prefixMap
262-
* @param array<int> $userRoles
262+
* @param array<string, int|string> $userRoles
263263
* @param array<int> $availableRoles
264264
*
265265
* @return bool
@@ -440,7 +440,7 @@ protected function _constructIniKey($params) {
440440
* Configure first, tries database roles table next.
441441
*
442442
* @throws \Cake\Core\Exception\CakeException
443-
* @return array<int> List with all available roles
443+
* @return array<string, int> List with all available roles
444444
*/
445445
protected function _getAvailableRoles() {
446446
if ($this->_roles !== null) {
@@ -514,7 +514,7 @@ protected function _getRolesFromDb(string $rolesTableKey): array {
514514
*
515515
* @param array $user The user to get the roles for
516516
* @throws \Cake\Core\Exception\CakeException
517-
* @return array<int> List with all role ids belonging to the user
517+
* @return array<string, int|string> List with all role ids belonging to the user
518518
*/
519519
protected function _getUserRoles($user) {
520520
// Single-role from session
@@ -610,8 +610,8 @@ protected function _getRolesFromJunction($pivotTableName, $id) {
610610
/**
611611
* Returns current roles as [alias => id] pairs.
612612
*
613-
* @param array<int> $roles
614-
* @return array<int>
613+
* @param array<int|string|\BackedEnum> $roles
614+
* @return array<string, int|string>
615615
*/
616616
protected function _mapped(array $roles) {
617617
$availableRoles = $this->_getAvailableRoles();
@@ -620,7 +620,8 @@ protected function _mapped(array $roles) {
620620
foreach ($roles as $role) {
621621
if ($role instanceof BackedEnum) {
622622
$alias = $role instanceof EnumLabelInterface ? $role->label() : $role->name;
623-
$array[$role->value] = $alias;
623+
$value = $role->value;
624+
$array[$alias] = $value;
624625

625626
continue;
626627
}

0 commit comments

Comments
 (0)