1 | <?php |
||
17 | class Roles |
||
18 | { |
||
19 | /** |
||
20 | * Old mylittleforum string based user roles |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $roles = []; |
||
25 | |||
26 | /** |
||
27 | * Shadows $this->roles for easy access with integer ID |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | private $rolesAsInt = []; |
||
32 | |||
33 | /** |
||
34 | * Adds a new role |
||
35 | * |
||
36 | * @param string $role Short title like 'user', 'mod', or 'admin' |
||
37 | * @param int $id A unique id for this role |
||
38 | * @param array $subroles Other roles this role represents |
||
39 | * @return self |
||
40 | */ |
||
41 | public function add(string $role, int $id, array $subroles = []): self |
||
49 | |||
50 | /** |
||
51 | * Get all roles for role |
||
52 | * |
||
53 | * @param string $role Role |
||
54 | * @param bool $includeAnon Include anon user |
||
55 | * @return array All roles a role has |
||
56 | */ |
||
57 | public function get(string $role, bool $includeAnon = true): array |
||
73 | |||
74 | /** |
||
75 | * Get all configured roles |
||
76 | * |
||
77 | * @param bool $includeAnon Include anon user |
||
78 | * @return array |
||
79 | */ |
||
80 | public function getAvailable(bool $includeAnon = false): array |
||
89 | |||
90 | /** |
||
91 | * Get role id for type |
||
92 | * |
||
93 | * @param string $type Type |
||
94 | * @return int |
||
95 | */ |
||
96 | public function typeToId(string $type): int |
||
104 | } |
||
105 |