casbin / swoole-redis-watcher
适用于 swoole 的 PHP-Casbin Redis 监视器。
v1.0.0
2021-11-22 11:14 UTC
Requires
- ext-redis: *
- ext-swoole: ^4.0
- casbin/casbin: ^3.0
README
在 PHP-Casbin 中为 Swoole 实现的 Redis 监视器,Casbin 是一个强大而高效的开源访问控制库。
安装
通过 Composer。
composer require casbin/swoole-redis-watcher
用法
require dirname(__FILE__) . '/../vendor/autoload.php'; use Casbin\Enforcer; use CasbinWatcher\SwooleRedis\Watcher; Co::set(['hook_flags'=> SWOOLE_HOOK_ALL]); $http = new Swoole\Http\Server('0.0.0.0', 9501); $http->on('WorkerStart', function ($server, $worker_id) { global $enforcer; // Initialize the Watcher. $watcher = new Watcher([ 'host' => '127.0.0.1', 'password' => '', 'port' => 6379, 'database' => 0, ]); // Initialize the Enforcer. $enforcer = new Enforcer("path/to/model.conf", "path/to/policy.csv"); // Set the watcher for the enforcer. $enforcer->setWatcher($watcher); // By default, the watcher's callback is automatically set to the // $enforcer->loadPolicy() in the setWatcher() call. // We can change it by explicitly setting a callback. $watcher->setUpdateCallback(function () use ($enforcer) { // Now should reload all policies. // $enforcer->loadPolicy(); }); }; $http->on('Request', function ($request, $response) { // ... }); $http->start();
获取帮助
许可协议
本项目采用 Apache 2.0 许可协议。