You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
8.3KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\rbac;
  8. /**
  9. * @author Qiang Xue <qiang.xue@gmail.com>
  10. * @since 2.0
  11. */
  12. interface ManagerInterface extends CheckAccessInterface
  13. {
  14. /**
  15. * Creates a new Role object.
  16. * Note that the newly created role is not added to the RBAC system yet.
  17. * You must fill in the needed data and call [[add()]] to add it to the system.
  18. * @param string $name the role name
  19. * @return Role the new Role object
  20. */
  21. public function createRole($name);
  22. /**
  23. * Creates a new Permission object.
  24. * Note that the newly created permission is not added to the RBAC system yet.
  25. * You must fill in the needed data and call [[add()]] to add it to the system.
  26. * @param string $name the permission name
  27. * @return Permission the new Permission object
  28. */
  29. public function createPermission($name);
  30. /**
  31. * Adds a role, permission or rule to the RBAC system.
  32. * @param Role|Permission|Rule $object
  33. * @return boolean whether the role, permission or rule is successfully added to the system
  34. * @throws \Exception if data validation or saving fails (such as the name of the role or permission is not unique)
  35. */
  36. public function add($object);
  37. /**
  38. * Removes a role, permission or rule from the RBAC system.
  39. * @param Role|Permission|Rule $object
  40. * @return boolean whether the role, permission or rule is successfully removed
  41. */
  42. public function remove($object);
  43. /**
  44. * Updates the specified role, permission or rule in the system.
  45. * @param string $name the old name of the role, permission or rule
  46. * @param Role|Permission|Rule $object
  47. * @return boolean whether the update is successful
  48. * @throws \Exception if data validation or saving fails (such as the name of the role or permission is not unique)
  49. */
  50. public function update($name, $object);
  51. /**
  52. * Returns the named role.
  53. * @param string $name the role name.
  54. * @return null|Role the role corresponding to the specified name. Null is returned if no such role.
  55. */
  56. public function getRole($name);
  57. /**
  58. * Returns all roles in the system.
  59. * @return Role[] all roles in the system. The array is indexed by the role names.
  60. */
  61. public function getRoles();
  62. /**
  63. * Returns the roles that are assigned to the user via [[assign()]].
  64. * Note that child roles that are not assigned directly to the user will not be returned.
  65. * @param string|integer $userId the user ID (see [[\yii\web\User::id]])
  66. * @return Role[] all roles directly assigned to the user. The array is indexed by the role names.
  67. */
  68. public function getRolesByUser($userId);
  69. /**
  70. * Returns the named permission.
  71. * @param string $name the permission name.
  72. * @return null|Permission the permission corresponding to the specified name. Null is returned if no such permission.
  73. */
  74. public function getPermission($name);
  75. /**
  76. * Returns all permissions in the system.
  77. * @return Permission[] all permissions in the system. The array is indexed by the permission names.
  78. */
  79. public function getPermissions();
  80. /**
  81. * Returns all permissions that the specified role represents.
  82. * @param string $roleName the role name
  83. * @return Permission[] all permissions that the role represents. The array is indexed by the permission names.
  84. */
  85. public function getPermissionsByRole($roleName);
  86. /**
  87. * Returns all permissions that the user has.
  88. * @param string|integer $userId the user ID (see [[\yii\web\User::id]])
  89. * @return Permission[] all permissions that the user has. The array is indexed by the permission names.
  90. */
  91. public function getPermissionsByUser($userId);
  92. /**
  93. * Returns the rule of the specified name.
  94. * @param string $name the rule name
  95. * @return null|Rule the rule object, or null if the specified name does not correspond to a rule.
  96. */
  97. public function getRule($name);
  98. /**
  99. * Returns all rules available in the system.
  100. * @return Rule[] the rules indexed by the rule names
  101. */
  102. public function getRules();
  103. /**
  104. * Checks the possibility of adding a child to parent
  105. * @param Item $parent the parent item
  106. * @param Item $child the child item to be added to the hierarchy
  107. * @return boolean possibility of adding
  108. *
  109. * @since 2.0.8
  110. */
  111. public function canAddChild($parent, $child);
  112. /**
  113. * Adds an item as a child of another item.
  114. * @param Item $parent
  115. * @param Item $child
  116. * @return boolean whether the child successfully added
  117. * @throws \yii\base\Exception if the parent-child relationship already exists or if a loop has been detected.
  118. */
  119. public function addChild($parent, $child);
  120. /**
  121. * Removes a child from its parent.
  122. * Note, the child item is not deleted. Only the parent-child relationship is removed.
  123. * @param Item $parent
  124. * @param Item $child
  125. * @return boolean whether the removal is successful
  126. */
  127. public function removeChild($parent, $child);
  128. /**
  129. * Removed all children form their parent.
  130. * Note, the children items are not deleted. Only the parent-child relationships are removed.
  131. * @param Item $parent
  132. * @return boolean whether the removal is successful
  133. */
  134. public function removeChildren($parent);
  135. /**
  136. * Returns a value indicating whether the child already exists for the parent.
  137. * @param Item $parent
  138. * @param Item $child
  139. * @return boolean whether `$child` is already a child of `$parent`
  140. */
  141. public function hasChild($parent, $child);
  142. /**
  143. * Returns the child permissions and/or roles.
  144. * @param string $name the parent name
  145. * @return Item[] the child permissions and/or roles
  146. */
  147. public function getChildren($name);
  148. /**
  149. * Assigns a role to a user.
  150. *
  151. * @param Role $role
  152. * @param string|integer $userId the user ID (see [[\yii\web\User::id]])
  153. * @return Assignment the role assignment information.
  154. * @throws \Exception if the role has already been assigned to the user
  155. */
  156. public function assign($role, $userId);
  157. /**
  158. * Revokes a role from a user.
  159. * @param Role $role
  160. * @param string|integer $userId the user ID (see [[\yii\web\User::id]])
  161. * @return boolean whether the revoking is successful
  162. */
  163. public function revoke($role, $userId);
  164. /**
  165. * Revokes all roles from a user.
  166. * @param mixed $userId the user ID (see [[\yii\web\User::id]])
  167. * @return boolean whether the revoking is successful
  168. */
  169. public function revokeAll($userId);
  170. /**
  171. * Returns the assignment information regarding a role and a user.
  172. * @param string $roleName the role name
  173. * @param string|integer $userId the user ID (see [[\yii\web\User::id]])
  174. * @return null|Assignment the assignment information. Null is returned if
  175. * the role is not assigned to the user.
  176. */
  177. public function getAssignment($roleName, $userId);
  178. /**
  179. * Returns all role assignment information for the specified user.
  180. * @param string|integer $userId the user ID (see [[\yii\web\User::id]])
  181. * @return Assignment[] the assignments indexed by role names. An empty array will be
  182. * returned if there is no role assigned to the user.
  183. */
  184. public function getAssignments($userId);
  185. /**
  186. * Returns all user IDs assigned to the role specified.
  187. * @param string $roleName
  188. * @return array array of user ID strings
  189. * @since 2.0.7
  190. */
  191. public function getUserIdsByRole($roleName);
  192. /**
  193. * Removes all authorization data, including roles, permissions, rules, and assignments.
  194. */
  195. public function removeAll();
  196. /**
  197. * Removes all permissions.
  198. * All parent child relations will be adjusted accordingly.
  199. */
  200. public function removeAllPermissions();
  201. /**
  202. * Removes all roles.
  203. * All parent child relations will be adjusted accordingly.
  204. */
  205. public function removeAllRoles();
  206. /**
  207. * Removes all rules.
  208. * All roles and permissions which have rules will be adjusted accordingly.
  209. */
  210. public function removeAllRules();
  211. /**
  212. * Removes all role assignments.
  213. */
  214. public function removeAllAssignments();
  215. }