PHPackages                             guanhui07/dcr-permission - 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. guanhui07/dcr-permission

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

guanhui07/dcr-permission
========================

webman casbin permission plugin

v1.0.0(2y ago)19MITPHPPHP &gt;=7.4

Since Jul 24Pushed 2y agoCompare

[ Source](https://github.com/guanhui07/dcr-permission)[ Packagist](https://packagist.org/packages/guanhui07/dcr-permission)[ RSS](/packages/guanhui07-dcr-permission/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

webman casbin plugin
====================

[](#webman-casbin-plugin)

[![Latest Stable Version](https://camo.githubusercontent.com/eaf1cd44a04e23cf30574a322cb681875e006c9b6b3e887197efa748d57de8fd/687474703a2f2f706f7365722e707567782e6f72672f63617362696e2f7765626d616e2d7065726d697373696f6e2f76)](https://packagist.org/packages/casbin/webman-permission)[![Total Downloads](https://camo.githubusercontent.com/73e2e0e9789f12ea96751fc91ae0fac641214a3d4ac3d76a44650ccac8d6e870/687474703a2f2f706f7365722e707567782e6f72672f63617362696e2f7765626d616e2d7065726d697373696f6e2f646f776e6c6f616473)](https://packagist.org/packages/casbin/webman-permission)[![Daily Downloads](https://camo.githubusercontent.com/faa7dc1b052ee41132d0b3982d0ade8425bccc40476241a00fc83c160d80a9bc/687474703a2f2f706f7365722e707567782e6f72672f63617362696e2f7765626d616e2d7065726d697373696f6e2f642f6461696c79)](https://packagist.org/packages/casbin/webman-permission)[![Latest Unstable Version](https://camo.githubusercontent.com/ff67dc368b31b5251ae2a7c861a2ba786586c80b145a7d27cda161f6d0a75815/687474703a2f2f706f7365722e707567782e6f72672f63617362696e2f7765626d616e2d7065726d697373696f6e2f762f756e737461626c65)](https://packagist.org/packages/casbin/webman-permission)[![License](https://camo.githubusercontent.com/f9eb5525474251ff8f7a7872ebec07006bc8b99a96b6e2325645b9a634be3283/687474703a2f2f706f7365722e707567782e6f72672f63617362696e2f7765626d616e2d7065726d697373696f6e2f6c6963656e7365)](https://packagist.org/packages/casbin/webman-permission)[![PHP Version Require](https://camo.githubusercontent.com/5d1ecc7ad4de411406d914876505a407084b376e68db0ae4b253d90de5b01c61/687474703a2f2f706f7365722e707567782e6f72672f63617362696e2f7765626d616e2d7065726d697373696f6e2f726571756972652f706870)](https://packagist.org/packages/casbin/webman-permission)

An authorization library that supports access control models like ACL, RBAC, ABAC for webman plugin

依赖
--

[](#依赖)

- [ThinkORM](https://www.workerman.net/doc/webman/db/others.html)（默认）
- [PHP-DI](https://github.com/PHP-DI/PHP-DI)
- [illuminate/database](https://www.workerman.net/doc/webman/db/tutorial.html)（可选）

安装
--

[](#安装)

```
composer require -W casbin/webman-permission
```

使用
--

[](#使用)

### 1. 依赖注入配置

[](#1-依赖注入配置)

修改配置`config/container.php`，其最终内容如下：

```
$builder = new \DI\ContainerBuilder();
$builder->addDefinitions(config('dependence', []));
$builder->useAutowiring(true);
return $builder->build();
```

### 2. 数据库配置

[](#2-数据库配置)

> 默认策略存储是使用的ThinkORM。 如使用 laravel的数据库 [illuminate/database](https://github.com/illuminate/database)，请按照官方文档按照相应的依赖包：

#### 🚀 (1) 模型配置

[](#-1-模型配置)

使用ThinkORM（默认）

> 修改数据库 `thinkorm.php` 配置

使用laravel数据库（可选）

> - 修改数据库 `database.php` 配置
> - 修改数据库 `permission.php` 的`adapter`适配器为laravel适配器

#### 🔰 (2) 创建 `casbin_rule` 数据表

[](#-2-创建-casbin_rule-数据表)

```
CREATE TABLE `casbin_rule` (
	`id` BIGINT ( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
	`ptype` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v0` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v1` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v2` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v3` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v4` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	`v5` VARCHAR ( 128 ) NOT NULL DEFAULT '',
	PRIMARY KEY ( `id` ) USING BTREE,
	KEY `idx_ptype` ( `ptype` ) USING BTREE,
	KEY `idx_v0` ( `v0` ) USING BTREE,
	KEY `idx_v1` ( `v1` ) USING BTREE,
	KEY `idx_v2` ( `v2` ) USING BTREE,
	KEY `idx_v3` ( `v3` ) USING BTREE,
	KEY `idx_v4` ( `v4` ) USING BTREE,
    KEY `idx_v5` ( `v5` ) USING BTREE
) ENGINE = INNODB CHARSET = utf8mb4 COMMENT = '策略规则表';
```

#### 📚 (3) 配置 `config/redis` 配置

[](#-3-配置-configredis-配置)

重启webman
--------

[](#重启webman)

```
php start.php restart

```

或者

```
php start.php restart -d

```

用法
--

[](#用法)

### 快速开始

[](#快速开始)

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

```
use Casbin\DcrPermission\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) 。

感谢
--

[](#感谢)

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

 解除 1、卸载DI依赖包：`composer remove php-di/php-di`

2、修改：`Casbin\DcrPermission\Permission` 文件

```
if (is_null(static::$_manager)) {
    static::$_manager = new Enforcer($model, Container::get($config['adapter']),false);
}
```

替换为

```
if (is_null(static::$_manager)) {
    if ($config['adapter'] == DatabaseAdapter::class) {
        $_model = new RuleModel();
    } elseif ($config['adapter'] == LaravelDatabaseAdapter::class) {
        $_model = new LaravelRuleModel();
    }
    static::$_manager = new Enforcer($model,  new $config['adapter']($_model), false);
}
```

耦合太高，不建议这么搞，更多了解：

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.2% 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

Unknown

Total

1

Last Release

1024d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3abde3fccf025ce86670101d7cfa0641d2415c9daad93e5f0c9573a2b23ddbda?d=identicon)[guanhui07](/maintainers/guanhui07)

---

Top Contributors

[![Tinywan](https://avatars.githubusercontent.com/u/14959876?v=4)](https://github.com/Tinywan "Tinywan (30 commits)")[![guanhui07](https://avatars.githubusercontent.com/u/5820457?v=4)](https://github.com/guanhui07 "guanhui07 (2 commits)")[![houaiai](https://avatars.githubusercontent.com/u/25687708?v=4)](https://github.com/houaiai "houaiai (1 commits)")[![leeqvip](https://avatars.githubusercontent.com/u/35752209?v=4)](https://github.com/leeqvip "leeqvip (1 commits)")

---

Tags

authorizationaclpermissionrbacaccess-controlabaccasbinauthzwebman

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/guanhui07-dcr-permission/health.svg)

```
[![Health](https://phpackages.com/badges/guanhui07-dcr-permission/health.svg)](https://phpackages.com/packages/guanhui07-dcr-permission)
```

###  Alternatives

[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[casbin/webman-permission

webman casbin permission plugin

523.4k2](/packages/casbin-webman-permission)[casbin/casbin

a powerful and efficient open-source access control library for php projects.

1.3k1.4M54](/packages/casbin-casbin)[casbin/think-authz

An authorization library that supports access control models like ACL, RBAC, ABAC for ThinkPHP.

27918.5k6](/packages/casbin-think-authz)[casbin/codeigniter-permission

Associate users with roles and permissions, use Casbin in CodeIgniter4 Web Framework.

443.0k](/packages/casbin-codeigniter-permission)[hosseinhezami/laravel-permission-manager

Advanced permission manager for Laravel.

403.3k](/packages/hosseinhezami-laravel-permission-manager)

PHPackages © 2026

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