|
1 | | -# dbal-adapter |
2 | | -Doctrine DBAL Adapter for Casbin, Casbin is a powerful and efficient open-source access control library. |
| 1 | +# Doctrine DBAL Adapter for Casbin |
| 2 | + |
| 3 | +[](https://travis-ci.org/php-casbin/dbal-adapter) |
| 4 | +[](https://coveralls.io/github/php-casbin/dbal-adapter) |
| 5 | +[](https://packagist.org/packages/casbin/dbal-adapter) |
| 6 | +[](https://packagist.org/packages/casbin/dbal-adapter) |
| 7 | +[](https://packagist.org/packages/casbin/dbal-adapter) |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +The following database vendors are currently supported: |
| 12 | + |
| 13 | +- MySQL |
| 14 | +- Oracle |
| 15 | +- Microsoft SQL Server |
| 16 | +- PostgreSQL |
| 17 | +- SAP Sybase SQL Anywhere |
| 18 | +- SQLite |
| 19 | +- Drizzle |
| 20 | + |
| 21 | +### Installation |
| 22 | + |
| 23 | +Via [Composer](https://getcomposer.org/). |
| 24 | + |
| 25 | +``` |
| 26 | +composer require casbin/dbal-adapter |
| 27 | +``` |
| 28 | + |
| 29 | +### Usage |
| 30 | + |
| 31 | +```php |
| 32 | + |
| 33 | +require_once './vendor/autoload.php'; |
| 34 | + |
| 35 | +use Casbin\Enforcer; |
| 36 | +use CasbinAdapter\DBAL\Adapter as DatabaseAdapter; |
| 37 | + |
| 38 | +$config = [ |
| 39 | + 'driver' => 'mysql', // ibm_db2, pdo_sqlsrv, pdo_mysql, pdo_pgsql, pdo_sqlite |
| 40 | + 'host' => '127.0.0.1', |
| 41 | + 'dbname' => 'test', |
| 42 | + 'user' => 'root', |
| 43 | + 'password' => '', |
| 44 | + 'port' => '3306', |
| 45 | +]; |
| 46 | + |
| 47 | +$adapter = DatabaseAdapter::newAdapter($config); |
| 48 | + |
| 49 | +$e = new Enforcer('path/to/model.conf', $adapter); |
| 50 | + |
| 51 | +$sub = "alice"; // the user that wants to access a resource. |
| 52 | +$obj = "data1"; // the resource that is going to be accessed. |
| 53 | +$act = "read"; // the operation that the user performs on the resource. |
| 54 | + |
| 55 | +if ($e->enforce($sub, $obj, $act) === true) { |
| 56 | + // permit alice to read data1 |
| 57 | +} else { |
| 58 | + // deny the request, show an error |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### Getting Help |
| 63 | + |
| 64 | +- [php-casbin](https://github.com/php-casbin/php-casbin) |
| 65 | + |
| 66 | +### License |
| 67 | + |
| 68 | +This project is licensed under the [Apache 2.0 license](LICENSE). |
0 commit comments