https://github.com/php-casbin/workerman-redis-watcher
Workerman Redis watcher for PHP-Casbin
https://github.com/php-casbin/workerman-redis-watcher
Last synced: 7 months ago
JSON representation
Workerman Redis watcher for PHP-Casbin
- Host: GitHub
- URL: https://github.com/php-casbin/workerman-redis-watcher
- Owner: php-casbin
- License: apache-2.0
- Created: 2021-11-09T10:29:41.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T16:15:35.000Z (over 1 year ago)
- Last Synced: 2025-04-01T07:38:44.560Z (about 1 year ago)
- Language: PHP
- Size: 9.77 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Workerman Redis watcher for PHP-Casbin
[](https://packagist.org/packages/casbin/workerman-redis-watcher)
[](https://packagist.org/packages/casbin/workerman-redis-watcher)
[](https://packagist.org/packages/casbin/workerman-redis-watcher)
[Workerman Redis](https://github.com/walkor/redis) watcher for [PHP-Casbin](https://github.com/php-casbin/php-casbin), [Casbin](https://casbin.org/) is a powerful and efficient open-source access control library.
### Installation
Via [Composer](https://getcomposer.org/).
```
composer require casbin/workerman-redis-watcher
```
### Usage
```php
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");
$enforcer->setWatcher($watcher);
// 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();
});
};
Worker::runAll();
```
### Getting Help
- [php-casbin](https://github.com/php-casbin/php-casbin)
### License
This project is licensed under the [Apache 2.0 license](LICENSE).