Skip to content

Repository files navigation

Database adapter for php-casbin

Build StatusCoverage StatusLatest Stable VersionTotal DownloadsLicense

Database adapter for PHP-Casbin.

The current supported databases are:

typedatabase
mysqlMySQL
pgsqlPostgreSQL
sqliteSQLite
sqlsrvSqlServer

Installation

Use Composer

composer require casbin/database-adapter

Usage

require_once'./vendor/autoload.php';
useCasbin\Enforcer;
useCasbin\Util\Log;
useCasbinAdapter\Database\AdapterasDatabaseAdapter;
$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 = newEnforcer('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.

About

Database adapter for PHP-Casbin, Casbin is a powerful and efficient open-source access control library.

Topics

Resources

Stars

30 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages