Workerman Redis watcher for PHP-Casbin
Workerman Redis watcher for PHP-Casbin, Casbin is a powerful and efficient open-source access control library.
Installation
Via Composer.
composer require casbin/workerman-redis-watcher
Usage
require dirname(__FILE__) . '/../vendor/autoload.php';
use Casbin\Enforcer;
use CasbinWatcher\WorkermanRedis\Watcher;
use Workerman\Worker;
$worker = new Worker();
$worker->count = 2;
$worker->onWorkerStart = function () {
// 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 callback, sets the callback function that the watcher will call,
// When the policy in DB has been changed by other instances.
// A classic callback is $enforcer->loadPolicy().
$watcher->setUpdateCallback(function () use ($enforcer) {
echo "Now should reload all policies." . PHP_EOL;
$enforcer->loadPolicy();
});
$enforcer->setWatcher($watcher);
};
Worker::runAll();
Getting Help
License
This project is licensed under the Apache 2.0 license.