PHPackages                             hsk99/webman-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. hsk99/webman-permission

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

hsk99/webman-permission
=======================

webman casbin permission plugin

v1.0.1(3y ago)15281MITPHPPHP &gt;=7.3

Since Dec 28Pushed 3y agoCompare

[ Source](https://github.com/hsk99/webman-permission)[ Packagist](https://packagist.org/packages/hsk99/webman-permission)[ RSS](/packages/hsk99-webman-permission/feed)WikiDiscussions main Synced 3w ago

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

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

[](#webman-casbin-plugin)

[![Latest Stable Version](https://camo.githubusercontent.com/bd793610603553e34ef0e74713af741504b50b16f14601b075ab330758afe9ba/687474703a2f2f706f7365722e707567782e6f72672f68736b39392f7765626d616e2d7065726d697373696f6e2f76)](https://packagist.org/packages/hsk99/webman-permission)[![Total Downloads](https://camo.githubusercontent.com/8602ff4479c82541a40cb3774a233ff89f1e42673214f6998e606725c10d5005/687474703a2f2f706f7365722e707567782e6f72672f68736b39392f7765626d616e2d7065726d697373696f6e2f646f776e6c6f616473)](https://packagist.org/packages/hsk99/webman-permission)[![Daily Downloads](https://camo.githubusercontent.com/0e2b3bc325ed4b1ec93cc26566d8f06c11331b9c6ef336cff39f38fe6822560c/687474703a2f2f706f7365722e707567782e6f72672f68736b39392f7765626d616e2d7065726d697373696f6e2f642f6461696c79)](https://packagist.org/packages/hsk99/webman-permission)[![Latest Unstable Version](https://camo.githubusercontent.com/98534260c17d03f6d79e9a3f28ce3bd7f23bf80a59be91fccbf0a233aa9a86cc/687474703a2f2f706f7365722e707567782e6f72672f68736b39392f7765626d616e2d7065726d697373696f6e2f762f756e737461626c65)](https://packagist.org/packages/hsk99/webman-permission)[![License](https://camo.githubusercontent.com/16ebff8ef336fd4a295d7afa77b6faabec154281c6a8104f16e6557719a0b408/687474703a2f2f706f7365722e707567782e6f72672f68736b39392f7765626d616e2d7065726d697373696f6e2f6c6963656e7365)](https://packagist.org/packages/hsk99/webman-permission)[![PHP Version Require](https://camo.githubusercontent.com/792033827764b78127b8ca511a5534c7914c5a9ee42105961eade712df7edfd6/687474703a2f2f706f7365722e707567782e6f72672f68736b39392f7765626d616e2d7065726d697373696f6e2f726571756972652f706870)](https://packagist.org/packages/hsk99/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 hsk99/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\WebmanPermission\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\WebmanPermission\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

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80.6% 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 ~15 days

Total

2

Last Release

1260d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6bbea2ea0f86c0bb2bc54d2e80f97cd023fb17493b0b4d1944a5e99e8e87a708?d=identicon)[hsk99](/maintainers/hsk99)

---

Top Contributors

[![Tinywan](https://avatars.githubusercontent.com/u/14959876?v=4)](https://github.com/Tinywan "Tinywan (29 commits)")[![hsk99](https://avatars.githubusercontent.com/u/20775916?v=4)](https://github.com/hsk99 "hsk99 (5 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/hsk99-webman-permission/health.svg)

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

###  Alternatives

[casbin/webman-permission

webman casbin permission plugin

533.5k2](/packages/casbin-webman-permission)[casbin/laravel-authz

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

331361.0k4](/packages/casbin-laravel-authz)[casbin/casbin

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

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

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

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

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

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

Advanced permission manager for Laravel.

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

PHPackages © 2026

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