Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 9a242d6

Browse files
committed
First release
1 parent 4b6a5af commit 9a242d6

File tree

13 files changed

+720
-2
lines changed

13 files changed

+720
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

README.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1-
# thinkphp-adapter
2-
Casbin for Thinkphp
1+
# ThinkPHP-Casbin
2+
3+
一个专为ThinkPHP5.1定制的Casbin的扩展包( https://github.com/php-casbin/think-casbin )。
4+
5+
### 安装
6+
7+
在你的thinkphp项目里,通过`composer`安装这个扩展
8+
9+
```
10+
composer require casbin/think-adapter
11+
```
12+
13+
发布资源:
14+
15+
```
16+
php think casbin:publish
17+
```
18+
19+
这将自动创建model配置文件`config/casbin-basic-model.conf`,和Casbin的配置文件`config/casbin.php`
20+
21+
数据迁移:
22+
23+
执行前,请确保数据库连接信息配置正确,如需修改数据库连接信息或表名,可以修改`config/casbin.php`里的配置
24+
25+
```
26+
php think casbin:migrate
27+
```
28+
29+
这将会自动创建Casbin的策略表`casbin_rule`
30+
31+
### 用法
32+
33+
```php
34+
35+
use Casbin;
36+
37+
$sub = 'alice'; // the user that wants to access a resource.
38+
$obj = 'data1'; // the resource that is going to be accessed.
39+
$act = 'read'; // the operation that the user performs on the resource.
40+
41+
if (true === Casbin::enforce($sub, $obj, $act)) {
42+
// permit alice to read data1x
43+
echo 'permit alice to read data1';
44+
} else {
45+
// deny the request, show an error
46+
}
47+
```
48+
49+
### 自定义配置
50+
51+
`config/casbin-basic-model.conf`为Casbin的model文件
52+
53+
`config/casbin.php`为Casbin的adapter、db配置信息
54+
55+
56+
### 关于Casbin
57+
58+
Casbin官网文档 (https://casbin.org )查看更多用法。

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "casbin/think-adapter",
3+
"keywords": ["casbin", "thinkphp", "casbin-adapter", "database"],
4+
"description": "Use casbin in thinkphp. ",
5+
"authors": [
6+
{
7+
"name": "TechLee",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"license": "Apache-2.0",
12+
"require": {
13+
"topthink/think-migration": "^2.0",
14+
"casbin/casbin": "^0.1.4"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"CasbinAdapter\\Think\\": "src/"
19+
},
20+
"files": [
21+
"helper.php"
22+
]
23+
}
24+
25+
}

0 commit comments

Comments
 (0)