Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/php-casbin/database-adapter
Database adapter for PHP-Casbin, Casbin is a powerful and efficient open-source access control library.
https://github.com/php-casbin/database-adapter
casbin database-adapter orm permissions php-casbin
Last synced: about 10 hours ago
JSON representation
Database adapter for PHP-Casbin, Casbin is a powerful and efficient open-source access control library.
- Host: GitHub
- URL: https://github.com/php-casbin/database-adapter
- Owner: php-casbin
- License: apache-2.0
- Created: 2018-10-16T12:32:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T16:19:43.000Z (20 days ago)
- Last Synced: 2024-10-29T20:52:48.592Z (20 days ago)
- Topics: casbin, database-adapter, orm, permissions, php-casbin
- Language: PHP
- Homepage:
- Size: 45.9 KB
- Stars: 28
- Watchers: 6
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Database adapter for php-casbin
[![Build Status](https://github.com/php-casbin/database-adapter/actions/workflows/build.yml/badge.svg)](https://github.com/php-casbin/database-adapter/actions/workflows/build.yml)
[![Coverage Status](https://coveralls.io/repos/github/php-casbin/database-adapter/badge.svg)](https://coveralls.io/github/php-casbin/database-adapter)
[![Latest Stable Version](https://poser.pugx.org/casbin/database-adapter/v/stable)](https://packagist.org/packages/casbin/database-adapter)
[![Total Downloads](https://poser.pugx.org/casbin/database-adapter/downloads)](https://packagist.org/packages/casbin/database-adapter)
[![License](https://poser.pugx.org/casbin/database-adapter/license)](https://packagist.org/packages/casbin/database-adapter)Database adapter for [PHP-Casbin](https://github.com/php-casbin/php-casbin).
The current supported databases are:
| type | database |
| ------ | ------ |
| mysql | MySQL |
| pgsql | PostgreSQL |
| sqlite | SQLite |
| sqlsrv | SqlServer |### Installation
Use [Composer](https://getcomposer.org/)
```
composer require casbin/database-adapter
```### Usage
```php
require_once './vendor/autoload.php';
use Casbin\Enforcer;
use Casbin\Util\Log;
use CasbinAdapter\Database\Adapter as DatabaseAdapter;$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 = 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).