Skip to content

Doctrine DBAL Adapter for Casbin, Casbin is a powerful and efficient open-source access control library.

License

Notifications You must be signed in to change notification settings

php-casbin/dbal-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doctrine DBAL Adapter for Casbin

Build Status Coverage Status Latest Stable Version Total Downloads License

Doctrine DBAL Adapter for PHP-Casbin, Casbin is a powerful and efficient open-source access control library.

The following database vendors are currently supported:

  • MySQL
  • Oracle
  • Microsoft SQL Server
  • PostgreSQL
  • SAP Sybase SQL Anywhere
  • SQLite
  • Drizzle

Installation

Via Composer.

composer require casbin/dbal-adapter

Usage

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
}

Getting Help

License

This project is licensed under the Apache 2.0 license.