PHPackages                             qifen/casbin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. qifen/casbin

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

qifen/casbin
============

Webman Casbin Plugin

2.1(4y ago)0641MITPHPPHP &gt;=7.4

Since Mar 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/xsxs89757/casbin)[ Packagist](https://packagist.org/packages/qifen/casbin)[ RSS](/packages/qifen-casbin/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (9)Versions (3)Used By (1)

webman casbin 权限控制插件
====================

[](#webman-casbin-权限控制插件)

webman casbin 权限控制插件。它基于 [PHP-Casbin](https://github.com/php-casbin/php-casbin), 一个强大的、高效的开源访问控制框架，支持基于`ACL`, `RBAC`, `ABAC`等访问控制模型。

安装
--

[](#安装)

```
composer require qifen/casbin
```

配置
--

[](#配置)

### 数据库配置

[](#数据库配置)

（1）修改数据库 `database` 配置

（2）执行 `php phinx migrate -e dev -t 20210000000000_create_casbin_rule` 导入数据库

（3）配置 `config/redis` 配置

重启webman
--------

[](#重启webman)

```
php start.php restart

```

或者

```
php start.php restart -d

```

用法
--

[](#用法)

### 快速开始

[](#快速开始)

安装成功后，可以这样使用:

```
use Qifen\Casbin\Permission;

// adds permissions to a user
Permission::addPermissionForUser('eve', 'articles', 'read');
// adds a role for a user.
Permission::addRoleForUser('eve', 'writer');
// adds permissions to a rule
Permission::addPolicy('writer', 'articles','edit');
```

你可以检查一个用户是否拥有某个权限:

```
if (Permission::enforce("eve", "articles", "edit")) {
    echo '恭喜你！通过权限认证';
} else {
    echo '对不起，您没有该资源访问权限';
}
```

更多 `API` 参考 [Casbin API](https://casbin.org/docs/en/management-api) 。

为什么要使用Redis
-----------

[](#为什么要使用redis)

1. 由于webman是基于workerman的常驻内存框架。运行模式为多进程，而多进程中数据是互相隔离的。
2. 在webman中使用casbin，当`Enforcer`中的策略发生变化时，调用 `Watcher`，向消息队列（MQ）中推动消息，监听该消息队列的`Enforcer`收到后，自动刷新该实例中的策略
3. 这里通过 `workerman/redis` 的发布订阅模式实现

> 注意：在 `PHP-FPM` 环境下，并不需要Watcher，因为每个请求都是一个独立的fpm进程，都会实例化一个全新的`Enforcer`

感谢
--

[](#感谢)

[Casbin](https://github.com/php-casbin/php-casbin)，你可以查看全部文档在其 [官网](https://casbin.org/) 上。

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

1583d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/32379836?v=4)[xsxs89757](/maintainers/xsxs89757)[@xsxs89757](https://github.com/xsxs89757)

---

Top Contributors

[![xsxs89757](https://avatars.githubusercontent.com/u/32379836?v=4)](https://github.com/xsxs89757 "xsxs89757 (13 commits)")[![MustBeBlue](https://avatars.githubusercontent.com/u/163366625?v=4)](https://github.com/MustBeBlue "MustBeBlue (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/qifen-casbin/health.svg)

```
[![Health](https://phpackages.com/badges/qifen-casbin/health.svg)](https://phpackages.com/packages/qifen-casbin)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M130](/packages/roots-acorn)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M95](/packages/mongodb-laravel-mongodb)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[api-platform/laravel

API Platform support for Laravel

58170.8k14](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
