PHPackages                             sunsgne/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. [Security](/categories/security)
4. /
5. sunsgne/casbin

ActiveLibrary[Security](/categories/security)

sunsgne/casbin
==============

webman-casbin

1.0.0(4y ago)928MITPHPPHP &gt;=7.4

Since May 16Pushed 2y ago2 watchersCompare

[ Source](https://github.com/sunsgneayo/webman-casbin)[ Packagist](https://packagist.org/packages/sunsgne/casbin)[ RSS](/packages/sunsgne-casbin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (10)Used By (0)

[![sunsgne](https://camo.githubusercontent.com/e366b0a276ef18e50c689cb143c8f78eadfa2e14e8af4a8e9e1628362ad93f1e/68747470733a2f2f63646e2e6e696e65313132302e636e2f6c6f676f2d692e706e67)](https://camo.githubusercontent.com/e366b0a276ef18e50c689cb143c8f78eadfa2e14e8af4a8e9e1628362ad93f1e/68747470733a2f2f63646e2e6e696e65313132302e636e2f6c6f676f2d692e706e67)

**sunsgne/webman-casbin**

**🐬 webman casbin-based permission assignment management 🐬**

[![Latest Stable Version](https://camo.githubusercontent.com/76b2fc1d6d78ae0414bb7ecfd41fc350a053952718eedba31fedd483ea3e75a7/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f63617362696e2f76)](https://packagist.org/packages/sunsgne/casbin)[![Total Downloads](https://camo.githubusercontent.com/bce0c99589295de6eb8b5f3239c3bdcee5325aacf245c132a14108c92ad54ae9/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f63617362696e2f646f776e6c6f616473)](https://packagist.org/packages/sunsgne/casbin)[![Latest Unstable Version](https://camo.githubusercontent.com/1d752a9b243e25318a3ea484284736b951210ea1cba4440e9c9835a7561cbdd7/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f63617362696e2f762f756e737461626c65)](https://packagist.org/packages/sunsgne/casbin)[![License](https://camo.githubusercontent.com/fdf50d1682e168c3ebd988a09a487af91f13e55178cf7fe0e6fd3fac2dedc07e/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f63617362696e2f6c6963656e7365)](https://packagist.org/packages/sunsgne/casbin)[![PHP Version Require](https://camo.githubusercontent.com/672045f81de54d6c5f93c4ee95f4ecdfadaccfebb50a1060b9c8e5b1e8da3222/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f63617362696e2f726571756972652f706870)](https://packagist.org/packages/sunsgne/casbin)

webman casbin 权限认证
==================

[](#webman-casbin-权限认证)

基于php-casbin，与webman-permission不同之处是没有用thinkorm,然后解决了几个错误

依赖
--

[](#依赖)

- [tinywan-casbin](https://github.com/php-casbin/webman-permission)
- [Casbin](https://casbin.org)
- [PHP-DI](https://github.com/PHP-DI/PHP-DI)
- [illuminate/database](https://www.workerman.net/doc/webman/db/tutorial.html)

安装
--

[](#安装)

```
composer require  sunsgne/casbin
```

使用
--

[](#使用)

### 1. 依赖注入配置

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

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

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

### 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 = '策略规则表';
```

用法
--

[](#用法)

```
use sunsgne\Auth;

// adds permissions to a user
Auth::addPermissionForUser('user:1', '/api/backend/cap', 'get');
// adds a role for a user.
Auth::addRoleForUser('user:1', 'role:1');
// adds permissions to a rule
Auth::addPolicy('role:1', '/api/backend/login','post');
```

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

```
if (Auth::enforce("user:1", "/api/backend/login", "post")) {
    echo '恭喜你！通过权限认证';
} else {
    echo '对不起，您没有该资源访问权限';
}
```

获取角色|用户
-------

[](#获取角色用户)

```
$r =  Auth::getRolesForUser('uuid:1');
$u =  Auth::getUsersForRole('roleId:1');
$a =  Auth::enforce("uuid:1" , "roleId:1" ,"post");
```

### 响应

[](#响应)

```
 array:1 [
  0 => "roleId:1"
]
 array:1 [
  0 => "uuid:1"
]
true
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

8

Last Release

1460d ago

Major Versions

0.0.6 → 1.0.02022-05-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/65843af70bae47cda80e0386c0640e2e17e1f8c8a12ea8fade3e1297237b26f3?d=identicon)[sunsgneayo](/maintainers/sunsgneayo)

---

Top Contributors

[![sunsgneayo](https://avatars.githubusercontent.com/u/51745500?v=4)](https://github.com/sunsgneayo "sunsgneayo (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.4k37.3k](/packages/matomo-matomo)[genealabs/laravel-governor

Managing policy and control in Laravel.

201262.8k](/packages/genealabs-laravel-governor)[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)[bjorn-voesten/ciphersweet-for-laravel

1411.6k](/packages/bjorn-voesten-ciphersweet-for-laravel)

PHPackages © 2026

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