-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRole.php
More file actions
executable file
·77 lines (63 loc) · 1.5 KB
/
Role.php
File metadata and controls
executable file
·77 lines (63 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* Copyright (c) 2023. Ankio. All Rights Reserved.
*/
namespace library\rbac;
use cleanphp\base\Config;
class Role
{
protected static ?Role $instance = null;
private array $config;
/**
* @var true
*/
private bool $code;
public function __construct($rbac = [])
{
if ($rbac === null) $rbac = [];
$this->config = $rbac;
}
public static function init($rbac = null): ?Role
{
if (!isset(self::$instance) || self::$instance == null) {
$rbac_ = [];
if (!empty($rbac)) {
foreach ($rbac as $item) {
$rbac_[$item["id"]] = $item;
}
}
self::$instance = new Role(empty($rbac_) ? Config::getConfig("rbac") : $rbac_);
self::$instance->code = true;
}
return self::$instance;
}
public static function getList()
{
if(self::$instance==null)return null;
return self::$instance->list();
}
/**
* 获取角色列表
* @return mixed
*/
public function list()
{
return $this->config;
}
/**
* 获取指定id的角色信息
* @param $id
* @return array
*/
public function get($id): array
{
$ids = explode(",", $id);
$ret = [];
foreach ($ids as $id) {
if (isset($this->config[$id])) {
$ret = array_merge($ret, $this->config[$id]['auth']);
}
}
return $ret;
}
}