Skip to content

Commit e5d615d

Browse files
committed
First commit.
1 parent 29cc3e0 commit e5d615d

File tree

7 files changed

+543
-2
lines changed

7 files changed

+543
-2
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
/vendor/
3+
4+
composer.lock
5+
6+
.idea/
7+
*.iml
8+
9+
# coverage report
10+
/build

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: php
2+
sudo: false
3+
4+
php:
5+
- 7.1
6+
- 7.2
7+
- 7.3
8+
9+
services:
10+
- mysql
11+
12+
before_install:
13+
- travis_retry composer self-update
14+
- mysql -e 'create database if not exists casbin;'
15+
16+
install:
17+
- travis_retry composer install --no-suggest --no-interaction
18+
19+
script:
20+
- vendor/bin/phpunit --version
21+
- mkdir -p build/logs
22+
- vendor/bin/phpunit
23+
24+
after_script:
25+
- travis_retry vendor/bin/php-coveralls -v

README.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
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+
[![Build Status](https://travis-ci.org/php-casbin/dbal-adapter.svg?branch=master)](https://travis-ci.org/php-casbin/dbal-adapter)
4+
[![Coverage Status](https://coveralls.io/repos/github/php-casbin/dbal-adapter/badge.svg)](https://coveralls.io/github/php-casbin/dbal-adapter)
5+
[![Latest Stable Version](https://poser.pugx.org/casbin/dbal-adapter/v/stable)](https://packagist.org/packages/casbin/dbal-adapter)
6+
[![Total Downloads](https://poser.pugx.org/casbin/dbal-adapter/downloads)](https://packagist.org/packages/casbin/dbal-adapter)
7+
[![License](https://poser.pugx.org/casbin/dbal-adapter/license)](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).

composer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "casbin/dbal-adapter",
3+
"keywords": [
4+
"casbin",
5+
"database",
6+
"dbal",
7+
"rbac",
8+
"permission",
9+
"acl",
10+
"adapter"
11+
],
12+
"description": "Database Abstraction Layer adapter for php-casbin. ",
13+
"authors": [
14+
{
15+
"name": "TechLee",
16+
"email": "[email protected]"
17+
}
18+
],
19+
"license": "Apache-2.0",
20+
"require": {
21+
"casbin/casbin": "^1.0",
22+
"doctrine/dbal": "^2.6"
23+
},
24+
"require-dev": {
25+
"phpunit/phpunit": "~7.0",
26+
"php-coveralls/php-coveralls": "^2.1"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"CasbinAdapter\\DBAL\\": "src/"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"CasbinAdapter\\DBAL\\Tests\\": "tests/"
36+
}
37+
}
38+
}

phpunit.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false">
11+
<testsuites>
12+
<testsuite name="Application Test Suite">
13+
<directory>./tests/</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist processUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">./src</directory>
19+
</whitelist>
20+
</filter>
21+
<logging>
22+
<log type="coverage-clover" target="build/logs/clover.xml"/>
23+
<log type="coverage-html" target="build/html"/>
24+
</logging>
25+
<php>
26+
<env name="DB_DATABASE" value="casbin"/>
27+
</php>
28+
</phpunit>

0 commit comments

Comments
 (0)