Think-Casbin 专为 ThinkPHP 打造的轻量级访问控制库 项目简介
PHP-Casbin 是一个用 PHP 语言打造的轻量级开源访问控制框架( https://github.com/php-casbin... ),目前在 GitHub 开源。PHP-Casbin 采用了元模型的设计思想,支持多种经典的访问控制方案,如基于角色的访问控制 RBAC、基于属性的访问控制 ABAC 等。Think-Casbin一个专为ThinkPHP5.1定制的Casbin的扩展包( https://github.com/php-casbin... )。安装在你的thinkphp项目里,通过composer安装这个扩展composer require casbin/think-adapter发布资源:php think casbin:publish这将自动创建model配置文件config/casbin-basic-model.conf,和Casbin的配置文件config/casbin.php数据迁移:执行前,请确保数据库连接信息配置正确,如需修改数据库连接信息或表名,可以修改config/casbin.php里的配置php think casbin:migrate这将会自动创建Casbin的策略表casbin_rule用法use Casbin;
$sub = 'alice'; // the user that wants to access a resource.
$obj = 'data1'; // the resource that is going to be accessed.
$act = 'read'; // the operation that the user performs on the resource.
if (true === Casbin::enforce($sub, $obj, $act)) {
// permit alice to read data1
echo 'permit alice to read data1';
} else {
// deny the request, show an error
}自定义配置config/casbin-basic-model.conf为Casbin的model文件config/casbin.php为Casbin的adapter、db配置信息关于CasbinCasbin官网文档 (https://casbin.org )查看更多用法。
$sub = 'alice'; // the user that wants to access a resource.
$obj = 'data1'; // the resource that is going to be accessed.
$act = 'read'; // the operation that the user performs on the resource.
if (true === Casbin::enforce($sub, $obj, $act)) {
// permit alice to read data1
echo 'permit alice to read data1';
} else {
// deny the request, show an error
}自定义配置config/casbin-basic-model.conf为Casbin的model文件config/casbin.php为Casbin的adapter、db配置信息关于CasbinCasbin官网文档 (https://casbin.org )查看更多用法。