Skip to content

Commit

Permalink
1、简化配置文件读取
Browse files Browse the repository at this point in the history
2、策略模型支持多个,默认为第一个
  • Loading branch information
Tinywan committed Jun 1, 2022
1 parent 4628d87 commit f43144f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ class Permission implements Bootstrap
public static function start($worker)
{
if ($worker) {
$configType = config('plugin.casbin.webman-permission.permission.basic.model.config_type');
$driver = config('plugin.casbin.webman-permission.permission.default');
$config = config('plugin.casbin.webman-permission.permission.'.$driver);
$model = new Model();
if ('file' == $configType) {
$model->loadModel(config('plugin.casbin.webman-permission.permission.basic.model.config_file_path'));
} elseif ('text' == $configType) {
$model->loadModel(config('plugin.casbin.webman-permission.permission.basic.model.config_text'));
if ('file' == $config['model']['config_type']) {
$model->loadModel($config['model']['config_file_path']);
} elseif ('text' == $config['model']['config_type']) {
$model->loadModel($config['model']['config_text']);
}
if (is_null(static::$_manager)) {
static::$_manager = new Enforcer($model, Container::get(config('plugin.casbin.webman-permission.permission.basic.adapter')),false);
static::$_manager = new Enforcer($model, Container::get($config['adapter']),false);
}

$watcher = new RedisWatcher(config('redis.default'));
Expand Down
28 changes: 25 additions & 3 deletions src/config/plugin/casbin/webman-permission/permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,42 @@
*/
return [
'default' => 'basic',
// 基础配置
'basic' => [
# Model 设置
// 策略模型Model设置
'model' => [
'config_type' => 'file',
'config_file_path' => config_path() . '/plugin/casbin/webman-permission/rbac-model.conf',
'config_text' => '',
],
# 适配器
// 适配器
'adapter' => Casbin\WebmanPermission\Adapter\DatabaseAdapter::class, // ThinkORM 适配器
// 'adapter' => Casbin\WebmanPermission\Adapter\LaravelDatabaseAdapter::class, // Laravel 适配器
// 数据库设置
'database' => [
'connection' => '',
'rules_table' => 'casbin_rule',
'rules_name' => null
],
]
],
// 其他扩展配置
'abac' => [
// 策略模型Model设置
'model' => [
'config_type' => 'file',
'config_file_path' => config_path() . '/plugin/casbin/webman-permission/abac-model.conf',
'config_text' => '',
],
// 适配器
'adapter' => Casbin\WebmanPermission\Adapter\LaravelDatabaseAdapter::class,
// 数据库设置
'database' => [
// 数据库连接名称,不填为默认配置
'connection' => '',
// 策略表名(不含表前缀)
'rules_table' => 'casbin_rule',
// 策略表完整名称
'rules_name' => null
],
],
];

0 comments on commit f43144f

Please sign in to comment.