From 9fd269e4bb25a4708ccb4369586bd7fa63f62ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E5=B0=91=E6=B3=A2?= <756684177@qq.com> Date: Thu, 24 Feb 2022 14:31:58 +0800 Subject: [PATCH] =?UTF-8?q?workerman/redis=20=E5=8F=AA=E8=83=BD=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E5=9C=A8workerman=E7=9A=84=E8=BF=90=E8=A1=8C=E7=8E=AF?= =?UTF-8?q?=E5=A2=83,=E5=88=A4=E6=96=AD=E6=96=B9=E6=B3=95=E6=98=AF?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=B8=8B$worker=E6=98=AF=E4=B8=8D=E6=98=AFnu?= =?UTF-8?q?ll=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Permission.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Permission.php b/src/Permission.php index 21a9245..7769828 100644 --- a/src/Permission.php +++ b/src/Permission.php @@ -10,6 +10,7 @@ namespace Tinywan\Casbin; +use Casbin\CoreEnforcer; use Casbin\Enforcer; use Casbin\Exceptions\CasbinException; use Casbin\Model\Model; @@ -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(); + }); + } } /**