1 | <?php |
||
25 | abstract class BaseManager extends Component implements ManagerInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var array a list of role names that are assigned to every user automatically without calling [[assign()]]. |
||
29 | */ |
||
30 | public $defaultRoles = []; |
||
31 | |||
32 | |||
33 | /** |
||
34 | * Returns the named auth item. |
||
35 | * @param string $name the auth item name. |
||
36 | * @return Item the auth item corresponding to the specified name. Null is returned if no such item. |
||
37 | */ |
||
38 | abstract protected function getItem($name); |
||
39 | |||
40 | /** |
||
41 | * Returns the items of the specified type. |
||
42 | * @param int $type the auth item type (either [[Item::TYPE_ROLE]] or [[Item::TYPE_PERMISSION]] |
||
43 | * @return Item[] the auth items of the specified type. |
||
44 | */ |
||
45 | abstract protected function getItems($type); |
||
46 | |||
47 | /** |
||
48 | * Adds an auth item to the RBAC system. |
||
49 | * @param Item $item the item to add |
||
50 | * @return bool whether the auth item is successfully added to the system |
||
51 | * @throws \Exception if data validation or saving fails (such as the name of the role or permission is not unique) |
||
52 | */ |
||
53 | abstract protected function addItem($item); |
||
54 | |||
55 | /** |
||
56 | * Adds a rule to the RBAC system. |
||
57 | * @param Rule $rule the rule to add |
||
58 | * @return bool whether the rule is successfully added to the system |
||
59 | * @throws \Exception if data validation or saving fails (such as the name of the rule is not unique) |
||
60 | */ |
||
61 | abstract protected function addRule($rule); |
||
62 | |||
63 | /** |
||
64 | * Removes an auth item from the RBAC system. |
||
65 | * @param Item $item the item to remove |
||
66 | * @return bool whether the role or permission is successfully removed |
||
67 | * @throws \Exception if data validation or saving fails (such as the name of the role or permission is not unique) |
||
68 | */ |
||
69 | abstract protected function removeItem($item); |
||
70 | |||
71 | /** |
||
72 | * Removes a rule from the RBAC system. |
||
73 | * @param Rule $rule the rule to remove |
||
74 | * @return bool whether the rule is successfully removed |
||
75 | * @throws \Exception if data validation or saving fails (such as the name of the rule is not unique) |
||
76 | */ |
||
77 | abstract protected function removeRule($rule); |
||
78 | |||
79 | /** |
||
80 | * Updates an auth item in the RBAC system. |
||
81 | * @param string $name the name of the item being updated |
||
82 | * @param Item $item the updated item |
||
83 | * @return bool whether the auth item is successfully updated |
||
84 | * @throws \Exception if data validation or saving fails (such as the name of the role or permission is not unique) |
||
85 | */ |
||
86 | abstract protected function updateItem($name, $item); |
||
87 | |||
88 | /** |
||
89 | * Updates a rule to the RBAC system. |
||
90 | * @param string $name the name of the rule being updated |
||
91 | * @param Rule $rule the updated rule |
||
92 | * @return bool whether the rule is successfully updated |
||
93 | * @throws \Exception if data validation or saving fails (such as the name of the rule is not unique) |
||
94 | */ |
||
95 | abstract protected function updateRule($name, $rule); |
||
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | 163 | public function createRole($name) |
|
106 | |||
107 | /** |
||
108 | * @inheritdoc |
||
109 | */ |
||
110 | 156 | public function createPermission($name) |
|
116 | |||
117 | /** |
||
118 | * @inheritdoc |
||
119 | */ |
||
120 | 163 | public function add($object) |
|
135 | |||
136 | /** |
||
137 | * @inheritdoc |
||
138 | */ |
||
139 | 7 | public function remove($object) |
|
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | */ |
||
153 | 16 | public function update($name, $object) |
|
168 | |||
169 | /** |
||
170 | * @inheritdoc |
||
171 | */ |
||
172 | 42 | public function getRole($name) |
|
177 | |||
178 | /** |
||
179 | * @inheritdoc |
||
180 | */ |
||
181 | 21 | public function getPermission($name) |
|
186 | |||
187 | /** |
||
188 | * @inheritdoc |
||
189 | */ |
||
190 | 24 | public function getRoles() |
|
194 | |||
195 | /** |
||
196 | * Returns defaultRoles as array of Role objects |
||
197 | * @since 2.0.12 |
||
198 | * @return Role[] default roles. The array is indexed by the role names |
||
199 | */ |
||
200 | 12 | public function getDefaultRoleInstances() |
|
208 | |||
209 | /** |
||
210 | * @inheritdoc |
||
211 | */ |
||
212 | 18 | public function getPermissions() |
|
216 | |||
217 | /** |
||
218 | * Executes the rule associated with the specified auth item. |
||
219 | * |
||
220 | * If the item does not specify a rule, this method will return true. Otherwise, it will |
||
221 | * return the value of [[Rule::execute()]]. |
||
222 | * |
||
223 | * @param string|int $user the user ID. This should be either an integer or a string representing |
||
224 | * the unique identifier of a user. See [[\yii\web\User::id]]. |
||
225 | * @param Item $item the auth item that needs to execute its rule |
||
226 | * @param array $params parameters passed to [[CheckAccessInterface::checkAccess()]] and will be passed to the rule |
||
227 | * @return bool the return value of [[Rule::execute()]]. If the auth item does not specify a rule, true will be returned. |
||
228 | * @throws InvalidConfigException if the auth item has an invalid rule. |
||
229 | */ |
||
230 | 24 | protected function executeRule($user, $item, $params) |
|
242 | |||
243 | /** |
||
244 | * Checks whether array of $assignments is empty and [[defaultRoles]] property is empty as well |
||
245 | * |
||
246 | * @param Assignment[] $assignments array of user's assignments |
||
247 | * @return bool whether array of $assignments is empty and [[defaultRoles]] property is empty as well |
||
248 | * @since 2.0.11 |
||
249 | */ |
||
250 | 32 | protected function hasNoAssignments(array $assignments) |
|
254 | } |
||
255 |