Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
workerman/redis 只能运行在workerman的运行环境,判断方法是判断下$worker是不是null。
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinywan committed Feb 24, 2022
1 parent 4908f2f commit 9fd269e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Tinywan\Casbin;


use Casbin\CoreEnforcer;
use Casbin\Enforcer;
use Casbin\Exceptions\CasbinException;
use Casbin\Model\Model;
Expand Down Expand Up @@ -59,22 +60,24 @@ class Permission implements Bootstrap
*/
public static function start($worker)
{
$configType = config('plugin.tinywan.casbin.permission.basic.model.config_type');
$model = new Model();
if ('file' == $configType) {
$model->loadModel(config('plugin.tinywan.casbin.permission.basic.model.config_file_path'));
} elseif ('text' == $configType) {
$model->loadModel(config('plugin.tinywan.casbin.permission.basic.model.config_text'));
}
if (is_null(static::$_manager)) {
static::$_manager = new Enforcer($model, Container::get(config('plugin.tinywan.casbin.permission.basic.adapter')),false);
}
if ($worker) {
$configType = config('plugin.tinywan.casbin.permission.basic.model.config_type');
$model = new Model();
if ('file' == $configType) {
$model->loadModel(config('plugin.tinywan.casbin.permission.basic.model.config_file_path'));
} elseif ('text' == $configType) {
$model->loadModel(config('plugin.tinywan.casbin.permission.basic.model.config_text'));
}
if (is_null(static::$_manager)) {
static::$_manager = new Enforcer($model, Container::get(config('plugin.tinywan.casbin.permission.basic.adapter')),false);
}

$watcher = new RedisWatcher(config('redis.default'));
static::$_manager->setWatcher($watcher);
$watcher->setUpdateCallback(function () {
static::$_manager->loadPolicy();
});
$watcher = new RedisWatcher(config('redis.default'));
static::$_manager->setWatcher($watcher);
$watcher->setUpdateCallback(function () {
static::$_manager->loadPolicy();
});
}
}

/**
Expand Down

0 comments on commit 9fd269e

Please sign in to comment.