luizpinheiro / acl
一个简单且与模型无关的访问控制列表管理器
v0.1.10
2019-03-26 02:00 UTC
Requires
- php: >=5.6.4
- illuminate/support: 5.3.*
This package is auto-updated.
Last update: 2024-09-26 15:08:49 UTC
README
警告:这个库目前正在建设中。
使用这个库,您可以检查基于角色的权限列表来控制对您的应用程序的访问。它是完全与模型无关的,例如,您可以(实际上您必须)定义自己的角色、权限和组管理实现。
该库提供了3个合约(接口)来帮助您构建管理类。您不需要实现所有的3个接口。如果您只想检查使用权限而不想创建角色或组,您只需实现PermissionsManagerContract。
如果您想将权限分组到角色中并将角色关联到用户,您必须实现RolesManagerContract。如果您想将角色(和权限)组织到组中,您必须实现GroupsManagerContract。
前往/examples目录以查找一些示例代码。
在下面的代码片段中,我们假设$roleManager实现了RolesManagerContract。
#Put this on the boostrap of your application use ACL\ACL; ACL::setRolesManager($roleManager) ACL::setPermissionsManager($permissionsManager); ACL::setGroupsManager($groupsManager); #you should tell the ACL who is the user, you should do this in your authorization #layer ACL::setUserId($user_id); #now you can check if the user has the permission ACL::hasPermission('documents.delete');