Skip to content

php-casbin/swoole-redis-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis watcher for PHP-Casbin in Swoole

Latest Stable Version Total Downloads License

Redis watcher for PHP-Casbin in Swoole , Casbin is a powerful and efficient open-source access control library.

Installation

Via Composer.

composer require casbin/swoole-redis-watcher

Usage

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();

Getting Help

License

This project is licensed under the Apache 2.0 license.

About

Redis watcher for PHP-Casbin in Swoole.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages