Forked from php-casbin/database-adapter
This is a database adapter for PHP-Casbin rewritten to use MySQLi only.
It does not use PDO or leeqvip/database.
MySQL databases are supported by instantiating a native PHP MySQLi connection and passing it into the constructor.
Use Composer and add the following to your composer.json:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Indexify-Finance/php-casbin-mysqli-adapter"
}
],
"require": {
"indexify/php-casbin-mysqli-adapter": "dev-master"
}
}Then run:
composer updaterequire_once './vendor/autoload.php';
use Casbin\Enforcer;
use PhpCasbinMysqliAdapter\Database\Adapter as DatabaseAdapter;
$connection = new mysqli(
'localhost', // hostname
'username', // database username
'password', // database password
'database_name' // database name
);
$adapter = DatabaseAdapter::newAdapter($connection, policy_table_name: 'casbin_rule');
$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
}This project is licensed under the Apache 2.0 license.