casbin/laminas-db-adapter
最新稳定版本:v2.0.0
Composer 安装命令:
composer require casbin/laminas-db-adapter
包简介
Laminas DB Adapter for Casbin, Casbin is a powerful and efficient open-source access control library.
README 文档
README
Laminas-db adapter for PHP-Casbin.
The list of officially supported drivers:
IbmDb2: The ext/ibm_db2 driverMysqli: The ext/mysqli driverOci8: The ext/oci8 driverPgsql: The ext/pgsql driverSqlsrv: The ext/sqlsrv driver (from Microsoft)Pdo_Mysql: MySQL via the PDO extensionPdo_Sqlite: SQLite via the PDO extensionPdo_Pgsql: PostgreSQL via the PDO extension
Installation
Use Composer.
composer require casbin/laminas-db-adapter
Usage
Before using it, you need to create a table named casbin_rule for Casbin to store the policy.
Take mysql as an example:
CREATE TABLE `casbin_rule` ( `ptype` varchar(255) NOT NULL, `v0` varchar(255) DEFAULT NULL, `v1` varchar(255) DEFAULT NULL, `v2` varchar(255) DEFAULT NULL, `v3` varchar(255) DEFAULT NULL, `v4` varchar(255) DEFAULT NULL, `v5` varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Then you can start like this:
require_once './vendor/autoload.php'; use Casbin\Enforcer; use Casbin\Util\Log; use CasbinAdapter\LaminasDb\Adapter; $adapter = new Adapter([ 'driver' => 'Pdo_Mysql', // IbmDb2, Mysqli, Oci8, Pgsql, Sqlsrv, Pdo_Mysql, Pdo_Sqlite, Pdo_Pgsql 'hostname' => '127.0.0.1', 'database' => 'test', 'username' => 'root', 'password' => '', 'port' => '3306', ]); $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 }
Getting Help
License
This project is licensed under the Apache 2.0 license.
统计信息
- 总下载量: 3.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2020-03-09