Open lzhlo opened 4 weeks ago
在源码里找了半天没找到,将数据加载到redis里面的代码,只找到LaravelDatabaseAdapter.php适配器的100行左右 public function loadPolicy(Model $model): void { $rows = $this->model->select(['ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5'])->get()->toArray();; foreach ($rows as $row) { $this->loadPolicyArray($this->filterRule($row), $model); } } 调用AdapterHelper.php的loadPolicyArray方法 public function loadPolicyArray(array $rule, Model $model): void {
在源码里找了半天没找到,将数据加载到redis里面的代码,只找到LaravelDatabaseAdapter.php适配器的100行左右
LaravelDatabaseAdapter.php
public function loadPolicy(Model $model): void { $rows = $this->model->select(['ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5'])->get()->toArray();; foreach ($rows as $row) { $this->loadPolicyArray($this->filterRule($row), $model); } }
调用AdapterHelper.php的loadPolicyArray方法
AdapterHelper.php
loadPolicyArray
public function loadPolicyArray(array $rule, Model $model): void {
$key = $rule[0]; $sec = $key[0]; if (!isset($model[$sec][$key])) { return; } $assertions = $model[$sec]; $assertion = $assertions[$key]; if (!($assertion instanceof Assertion)) { return; } $rule = \array_slice($rule, 1); $assertion->policy[] = $rule; $assertion->policyMap[implode(Policy::DEFAULT_SEP, $rule)] = count($assertion->policy) - 1; $assertions[$key] = $assertion; $model[$sec] = $assertions; }
只找到了订阅部分的代码没找到往redis里写入数据的代码 ```php static::$_manager[$driver] = new Enforcer($model, Container::make($config['adapter'], [$driver]), false); $watcher = new RedisWatcher(config('redis.default'), $driver); static::$_manager[$driver]->setWatcher($watcher); $watcher->setUpdateCallback(function () use ($driver) { static::$_manager[$driver]->loadPolicy(); }); return static::$_manager[$driver];
redis只是负责发布订阅,数据不会写到redis