Skip to content

Commit

Permalink
fix: restful-model.conf 适配器
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinywan committed Mar 12, 2023
1 parent 49cf201 commit c78c418
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Model/RuleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RuleModel extends Model implements Arrayable
];

/** @var string|null $driver */
protected ?string $driver;
protected ?string $driver;

/**
* 架构函数
Expand All @@ -61,7 +61,7 @@ public function __construct(array $data = [], ?string $driver = null)
*/
protected function config(string $key = null, $default = null)
{
$driver = $this->driver ?: config('plugin.casbin.webman-permission.permission.default');
$driver = $this->driver ?? config('plugin.casbin.webman-permission.permission.default');
return config('plugin.casbin.webman-permission.permission.' . $driver . '.' . $key, $default);
}
}
15 changes: 14 additions & 1 deletion src/config/plugin/casbin/webman-permission/permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
return [
'default' => 'basic',
// 基础配置
// 默认配置
'basic' => [
// 策略模型Model设置
'model' => [
Expand All @@ -25,4 +25,17 @@
],
],
// 其他扩展配置,只需要按照基础配置一样,复制一份,指定相关策略模型和适配器即可
'restful' => [
'model' => [
'config_type' => 'file',
'config_file_path' => config_path() . '/plugin/casbin/webman-permission/restful-model.conf',
'config_text' => '',
],
'adapter' => Casbin\WebmanPermission\Adapter\DatabaseAdapter::class, // ThinkORM 适配器
'database' => [
'connection' => '',
'rules_table' => 'restful_casbin_rule',
'rules_name' => null
],
],
];
11 changes: 11 additions & 0 deletions src/config/plugin/casbin/webman-permission/restful-model.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = r.sub == p.sub && keyMatch2(r.obj, p.obj) && regexMatch(r.act, p.act)

0 comments on commit c78c418

Please sign in to comment.