casbin / database-adapter
php-casbin的数据库适配器。
v1.8.0
2022-10-23 10:54 UTC
Requires
- casbin/casbin: ^3.0
- leeqvip/database: ^1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ~7.0|~8.0|~9.0
README
PHP-Casbin的数据库适配器。
当前支持的数据库包括
安装
使用Composer
composer require casbin/database-adapter
使用方法
require_once './vendor/autoload.php'; use Casbin\Enforcer; use Casbin\Util\Log; use CasbinAdapter\Database\Adapter as DatabaseAdapter; $config = [ 'type' => 'mysql', // mysql,pgsql,sqlite,sqlsrv 'hostname' => '127.0.0.1', 'database' => 'test', 'username' => 'root', 'password' => 'abc-123', 'hostport' => '3306', ]; $adapter = DatabaseAdapter::newAdapter($config); $e = new Enforcer('path/to/model.conf', $adapter); $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 ($e->enforce($sub, $obj, $act) === true) { // permit alice to read data1 } else { // deny the request, show an error }
获取帮助
许可证
本项目采用Apache 2.0许可证。