diff --git a/src/Model/RuleModel.php b/src/Model/RuleModel.php index 466b9ce..f7685fb 100644 --- a/src/Model/RuleModel.php +++ b/src/Model/RuleModel.php @@ -35,7 +35,7 @@ class RuleModel extends Model implements Arrayable ]; /** @var string|null $driver */ - protected ?string $driver; + protected ?string $driver; /** * 架构函数 @@ -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); } } \ No newline at end of file diff --git a/src/config/plugin/casbin/webman-permission/permission.php b/src/config/plugin/casbin/webman-permission/permission.php index 7a4adfe..ce867ac 100644 --- a/src/config/plugin/casbin/webman-permission/permission.php +++ b/src/config/plugin/casbin/webman-permission/permission.php @@ -6,7 +6,7 @@ */ return [ 'default' => 'basic', - // 基础配置 + // 默认配置 'basic' => [ // 策略模型Model设置 'model' => [ @@ -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 + ], + ], ]; \ No newline at end of file diff --git a/src/config/plugin/casbin/webman-permission/restful-model.conf b/src/config/plugin/casbin/webman-permission/restful-model.conf new file mode 100644 index 0000000..944123d --- /dev/null +++ b/src/config/plugin/casbin/webman-permission/restful-model.conf @@ -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) \ No newline at end of file