Tinywan / webman-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC for webman plugin
https://www.workerman.net/webman
Apache License 2.0
11 stars 0 forks source link

webman-console 命令行运行报错 #2

Open yuanzhihai opened 2 years ago

yuanzhihai commented 2 years ago

PHP Fatal error: Uncaught Error: Call to a member function add() on null in /Users/yuanzhihai/Sites/local/webman/vendor/workerman/workerman/Connection/AsyncTcpConnection.php:213 Stack trace:

0 /Users/yuanzhihai/Sites/local/webman/vendor/workerman/redis/src/Client.php(444): Workerman\Connection\AsyncTcpConnection->connect()

1 /Users/yuanzhihai/Sites/local/webman/vendor/workerman/redis/src/Client.php(275): Workerman\Redis\Client->connect()

2 /Users/yuanzhihai/Sites/local/webman/vendor/tinywan/casbin/src/Watcher/RedisWatcher.php(94): Workerman\Redis\Client->__construct('redis://127.0.0...')

3 /Users/yuanzhihai/Sites/local/webman/vendor/tinywan/casbin/src/Watcher/RedisWatcher.php(40): Tinywan\Casbin\Watcher\RedisWatcher->createRedisClient(Array)

4 /Users/yuanzhihai/Sites/local/webman/vendor/tinywan/casbin/src/Permission.php(73): Tinywan\Casbin\Watcher\RedisWatcher->__construct(Array)

5 /Users/yuanzhihai/Sites/local/webman/support/bootstrap.php(77): Tinywan\Casbin\Permission::start(NULL)

6 /Users/yuanzhihai/Sites/local/webman/webman(6): require_once('/Users/yuanzhih...')

7 {main}

thrown in /Users/yuanzhihai/Sites/local/webman/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 213

yuanzhihai commented 2 years ago

使用 webman 命令行 报错的

Tinywan commented 2 years ago

你的Redis配偶配置了没有?

yuanzhihai commented 2 years ago

配置了

'default' => [ 'host' => '127.0.0.1', 'password' => null, 'port' => 6379, 'database' => 0, ], 我队列使用的好好的

Tinywan commented 2 years ago

你下载个最新版本的webman试试,你这是部分文件没升级导致的

yuanzhihai commented 2 years ago

一样的

walkor commented 2 years ago
image

https://github.com/Tinywan/casbin/blob/4908f2fff39f5086a7c67ec0d012d9ec195a79a0/src/Permission.php#L60

workerman/redis 只能运行在workerman的运行环境,所以在Tinywan\Casbin\Permission::start($worker)方法里要判断下是不是workerman的运行环境。判断方法是判断下$worker是不是null。 如果是null就不做casbin初始化或者选择性初始化,避免报错。

Tinywan commented 2 years ago

@yzh52521 使用最新版本 v0.0.8