casbin / dbal-adapter
php-casbin的数据库抽象层适配器。
v2.4.1
2024-07-22 13:52 UTC
Requires
- casbin/casbin: ^3.0
- doctrine/dbal: ^2.9|^3.0|^4.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ~7.0|~8.0
README
Doctrine DBAL 适配器用于 PHP-Casbin,Casbin 是一个强大且高效的开源访问控制库。
当前支持以下数据库供应商
- MySQL
- Oracle
- Microsoft SQL Server
- PostgreSQL
- SAP Sybase SQL Anywhere
- SQLite
- Drizzle
安装
通过 Composer。
composer require casbin/dbal-adapter
用法
require_once './vendor/autoload.php'; use Casbin\Enforcer; use CasbinAdapter\DBAL\Adapter as DatabaseAdapter; $config = [ // Either 'driver' with one of the following values: // pdo_mysql,pdo_sqlite,pdo_pgsql,pdo_oci (unstable),pdo_sqlsrv // mysqli,sqlanywhere,sqlsrv,ibm_db2 (unstable),drizzle_pdo_mysql 'driver' => 'pdo_mysql', 'host' => '127.0.0.1', 'dbname' => 'test', 'user' => 'root', 'password' => '', 'port' => '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 许可协议。