casbin/medoo-adapter

php-casbin的Medoo适配器。

v1.7.0 2021-09-13 14:53 UTC

This package is auto-updated.

Last update: 2024-08-29 05:08:20 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

Medoo 适配器用于 PHP-CasbinCasbin 是一个强大且高效的开源访问控制库。

Medoo 是一个轻量级的PHP数据库框架,用于加速开发,支持所有SQL数据库,包括 MySQLMSSQLSQLiteMariaDBPostgreSQLSybaseOracle 以及更多。

安装

通过 Composer

composer require casbin/medoo-adapter

用法

require_once './vendor/autoload.php';

use Casbin\Enforcer;
use CasbinAdapter\Medoo\Adapter as DatabaseAdapter;

$config = [
    'database_type' => 'mysql',
    'server' => '127.0.0.1',
    'database_name' => 'test',
    'username' => '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 许可协议