1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebComplete\rbac; |
4
|
|
|
|
5
|
|
|
use WebComplete\rbac\entity\PermissionInterface; |
6
|
|
|
use WebComplete\rbac\entity\RoleInterface; |
7
|
|
|
use WebComplete\rbac\resource\ResourceInterface; |
8
|
|
|
|
9
|
|
|
class Rbac implements RbacInterface |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var ResourceInterface |
14
|
|
|
*/ |
15
|
|
|
protected $resource; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param ResourceInterface $resource |
19
|
|
|
* |
20
|
|
|
* @throws \WebComplete\rbac\exception\RbacException |
21
|
|
|
*/ |
22
|
|
|
public function __construct(ResourceInterface $resource) |
23
|
|
|
{ |
24
|
|
|
$this->resource = $resource; |
25
|
|
|
$this->resource->load(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $name |
30
|
|
|
* |
31
|
|
|
* @return RoleInterface |
32
|
|
|
*/ |
33
|
|
|
public function createRole(string $name): RoleInterface |
34
|
|
|
{ |
35
|
|
|
return $this->resource->createRole($name); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $name |
40
|
|
|
* @param string $description |
41
|
|
|
* |
42
|
|
|
* @return PermissionInterface |
43
|
|
|
* @throws \WebComplete\rbac\exception\RbacException |
44
|
|
|
*/ |
45
|
|
|
public function createPermission(string $name, string $description): PermissionInterface |
46
|
|
|
{ |
47
|
|
|
return $this->resource->createPermission($name, $description); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return RoleInterface[] |
52
|
|
|
*/ |
53
|
|
|
public function getRoles(): array |
54
|
|
|
{ |
55
|
|
|
return $this->resource->getRoles(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $name |
60
|
|
|
* |
61
|
|
|
* @return RoleInterface|null |
62
|
|
|
*/ |
63
|
|
|
public function getRole(string $name) |
64
|
|
|
{ |
65
|
|
|
return $this->resource->getRole($name); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $name |
70
|
|
|
*/ |
71
|
|
|
public function deleteRole(string $name) |
72
|
|
|
{ |
73
|
|
|
$this->resource->deleteRole($name); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return PermissionInterface[] |
78
|
|
|
*/ |
79
|
|
|
public function getPermissions(): array |
80
|
|
|
{ |
81
|
|
|
return $this->resource->getPermissions(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $name |
86
|
|
|
* |
87
|
|
|
* @return PermissionInterface|null |
88
|
|
|
*/ |
89
|
|
|
public function getPermission(string $name) |
90
|
|
|
{ |
91
|
|
|
return $this->resource->getPermission($name); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $name |
96
|
|
|
*/ |
97
|
|
|
public function deletePermission(string $name) |
98
|
|
|
{ |
99
|
|
|
$this->resource->deletePermission($name); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
*/ |
104
|
|
|
public function clear() |
105
|
|
|
{ |
106
|
|
|
$this->resource->clear(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @throws \WebComplete\rbac\exception\RbacException |
111
|
|
|
*/ |
112
|
|
|
public function load() |
113
|
|
|
{ |
114
|
|
|
$this->resource->load(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @throws \WebComplete\rbac\exception\RbacException |
119
|
|
|
*/ |
120
|
|
|
public function save() |
121
|
|
|
{ |
122
|
|
|
$this->resource->save(); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|