PHP code example of donjan-deng / hyperf-casbin
1. Go to this page and download the library: Download donjan-deng/hyperf-casbin library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
donjan-deng / hyperf-casbin example snippets
use Donjan\Casbin\Enforcer;
为用户添加权限
Enforcer::addPermissionForUser('user1', '/user', 'read');
删除一个用户的权限
Enforcer::deletePermissionForUser('user1', '/user', 'read');
获取用户所有权限
Enforcer::getPermissionsForUser('user1');
为用户添加角色
Enforcer::addRoleForUser('user1', 'role1');
为角色添加权限
Enforcer::addPermissionForUser('role1', '/user', 'edit');
获取所有角色
Enforcer::getAllRoles();
获取用户所有角色
Enforcer::getRolesForUser('user1');
根据角色获取用户
Enforcer::getUsersForRole('role1');
判断用户是否属于一个角色
Enforcer::hasRoleForUser('use1', 'role1');
删除用户角色
Enforcer::deleteRoleForUser('use1', 'role1');
删除用户所有角色
Enforcer::deleteRolesForUser('use1');
删除角色
Enforcer::deleteRole('role1');
删除权限
Enforcer::deletePermission('/user', 'read');
删除用户或者角色的所有权限
Enforcer::deletePermissionsForUser('user1');
Enforcer::deletePermissionsForUser('role1');
检查权限,返回 true or false
Enforcer::enforce("user1", "/user", "edit")
php bin/hyperf.php vendor:publish donjan-deng/hyperf-casbin