1 | <?php /** MicroRBAC */ |
||
22 | abstract class Rbac implements Adapter |
||
23 | { |
||
24 | /** @const integer TYPE_ROLE */ |
||
25 | const TYPE_ROLE = 0; |
||
26 | /** @const integer TYPE_PERMISSION */ |
||
27 | const TYPE_PERMISSION = 1; |
||
28 | /** @const integer TYPE_OPERATION */ |
||
29 | const TYPE_OPERATION = 2; |
||
30 | |||
31 | /** @var IDriver $db */ |
||
32 | protected $db; |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Based constructor for RBAC rules |
||
37 | * |
||
38 | * @access public |
||
39 | * |
||
40 | * @param IConnection $connection |
||
41 | * |
||
42 | * @result void |
||
43 | */ |
||
44 | public function __construct(IConnection $connection) |
||
56 | |||
57 | /** |
||
58 | * Assign RBAC element into user |
||
59 | * |
||
60 | * @access public |
||
61 | * |
||
62 | * @param integer $userId user id |
||
63 | * @param string $name element name |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | abstract public function assign($userId, $name); |
||
68 | |||
69 | /** |
||
70 | * Check privileges to operation |
||
71 | * |
||
72 | * @access public |
||
73 | * |
||
74 | * @param integer $userId user id |
||
75 | * @param string $permission permission name |
||
76 | * @param array $data action params |
||
77 | * |
||
78 | * @return boolean |
||
79 | * @throws \Micro\Base\Exception |
||
80 | */ |
||
81 | public function check($userId, $permission, array $data = []) |
||
106 | |||
107 | /** |
||
108 | * Get raw roles |
||
109 | * |
||
110 | * @access public |
||
111 | * @return mixed |
||
112 | */ |
||
113 | abstract public function rawRoles(); |
||
114 | |||
115 | /** |
||
116 | * Build tree from RBAC rules |
||
117 | * |
||
118 | * @access public |
||
119 | * |
||
120 | * @param array $elements elements array |
||
121 | * @param string $parentId parent ID |
||
122 | * |
||
123 | * @return array |
||
124 | */ |
||
125 | public function tree(&$elements, $parentId = '0') |
||
143 | |||
144 | /** |
||
145 | * Get assigned to user RBAC elements |
||
146 | * |
||
147 | * @access public |
||
148 | * |
||
149 | * @param integer $userId user ID |
||
150 | * |
||
151 | * @return mixed |
||
152 | * @throws \Micro\Base\Exception |
||
153 | */ |
||
154 | public function assigned($userId) |
||
165 | |||
166 | /** |
||
167 | * Recursive search in roles array |
||
168 | * |
||
169 | * @access public |
||
170 | * |
||
171 | * @param array $roles elements |
||
172 | * @param string $finder element name to search |
||
173 | * |
||
174 | * @return array|false |
||
175 | */ |
||
176 | protected function searchRoleRecursive($roles, $finder) |
||
193 | |||
194 | /** |
||
195 | * Execute rule |
||
196 | * |
||
197 | * @access public |
||
198 | * |
||
199 | * @param array $role element |
||
200 | * @param array $data action params |
||
201 | * |
||
202 | * @return bool |
||
203 | */ |
||
204 | public function execute(array $role, array $data) |
||
214 | |||
215 | /** |
||
216 | * Revoke RBAC element from user |
||
217 | * |
||
218 | * @access public |
||
219 | * |
||
220 | * @param integer $userId user id |
||
221 | * @param string $name element name |
||
222 | * |
||
223 | * @return bool |
||
224 | */ |
||
225 | public function revoke($userId, $name) |
||
230 | } |
||
231 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.