https://github.com/php-casbin/dbal-adapter
Doctrine DBAL Adapter for Casbin, Casbin is a powerful and efficient open-source access control library.
https://github.com/php-casbin/dbal-adapter
acl adapter casbin database dbal permission rbac
Last synced: 12 months ago
JSON representation
Doctrine DBAL Adapter for Casbin, Casbin is a powerful and efficient open-source access control library.
- Host: GitHub
- URL: https://github.com/php-casbin/dbal-adapter
- Owner: php-casbin
- License: apache-2.0
- Created: 2019-09-06T04:25:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-12-20T04:47:38.000Z (over 1 year ago)
- Last Synced: 2025-04-17T09:02:52.365Z (about 1 year ago)
- Topics: acl, adapter, casbin, database, dbal, permission, rbac
- Language: PHP
- Size: 41 KB
- Stars: 13
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Doctrine DBAL Adapter for Casbin
[](https://github.com/php-casbin/dbal-adapter/actions/workflows/phpunit.yml)
[](https://coveralls.io/github/php-casbin/dbal-adapter)
[](https://packagist.org/packages/casbin/dbal-adapter)
[](https://packagist.org/packages/casbin/dbal-adapter)
[](https://packagist.org/packages/casbin/dbal-adapter)
Doctrine [DBAL](https://github.com/doctrine/dbal) Adapter for [PHP-Casbin](https://github.com/php-casbin/php-casbin), [Casbin](https://casbin.org/) 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](https://getcomposer.org/).
```
composer require casbin/dbal-adapter
```
### Usage
```php
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
- [php-casbin](https://github.com/php-casbin/php-casbin)
### License
This project is licensed under the [Apache 2.0 license](LICENSE).