[USER] Add UserRoles
This commit is contained in:
parent
5a74354703
commit
f3ccdf8017
@ -31,22 +31,31 @@ namespace App\Core;
|
|||||||
*/
|
*/
|
||||||
abstract class UserRoles
|
abstract class UserRoles
|
||||||
{
|
{
|
||||||
const ADMIN = 1;
|
public const ADMIN = 1;
|
||||||
const MODERATOR = 2;
|
public const MODERATOR = 2;
|
||||||
const USER = 4;
|
public const USER = 4;
|
||||||
|
public const BOT = 8;
|
||||||
|
|
||||||
|
public static $consts = null;
|
||||||
|
|
||||||
public static function bitmapToStrings(int $r): array
|
public static function bitmapToStrings(int $r): array
|
||||||
{
|
{
|
||||||
$roles = [];
|
$roles = [];
|
||||||
$consts = (new ReflectionClass(__CLASS__))->getConstants();
|
if (self::$consts == null) {
|
||||||
while ($r != 0) {
|
self::$consts = (new \ReflectionClass(__CLASS__))->getConstants();
|
||||||
foreach ($consts as $c => $v) {
|
}
|
||||||
if ($r & $v !== 0) {
|
|
||||||
$r &= ~$v;
|
foreach (self::$consts as $c => $v) {
|
||||||
$roles[] = "ROLE_{$c}";
|
if (($r & $v) !== 0) {
|
||||||
}
|
$r -= $v;
|
||||||
|
$roles[] = "ROLE_{$c}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($r != 0) {
|
||||||
|
Log::error('User roles bitmap to array failed');
|
||||||
|
}
|
||||||
|
|
||||||
return $roles;
|
return $roles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user