PHPackages                             death\_satan/hyperf-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. death\_satan/hyperf-casbin

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

death\_satan/hyperf-casbin
==========================

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

v3.1.0(2y ago)01Apache-2.0PHPPHP &gt;=8.1

Since Jan 7Pushed 2y agoCompare

[ Source](https://github.com/zds-s/hyperf-casbin)[ Packagist](https://packagist.org/packages/death_satan/hyperf-casbin)[ RSS](/packages/death-satan-hyperf-casbin/feed)WikiDiscussions master Synced 1mo ago

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

Hyperf Casbin
=============

[](#hyperf-casbin)

[![Test](https://github.com/donjan-deng/hyperf-casbin/actions/workflows/test.yml/badge.svg)](https://github.com/donjan-deng/hyperf-casbin/actions/workflows/test.yml)[![Latest Stable Version](https://camo.githubusercontent.com/24dc8e8a63db37ddd5b6c51b64b49b828dec5c582d5768cb45dd11c7ef261e00/68747470733a2f2f706f7365722e707567782e6f72672f646f6e6a616e2d64656e672f6879706572662d63617362696e2f762f737461626c65)](https://packagist.org/packages/donjan-deng/hyperf-casbin)[![Total Downloads](https://camo.githubusercontent.com/37cd70a8cd9673c7ea4f59fd9f1aa35fcdf8f34d406163cd047be213d28b6c69/68747470733a2f2f706f7365722e707567782e6f72672f646f6e6a616e2d64656e672f6879706572662d63617362696e2f646f776e6c6f616473)](https://packagist.org/packages/donjan-deng/hyperf-casbin)[![License](https://camo.githubusercontent.com/6a05b56a79e98397e072d243d53c05b2a8be40c846ec1f939fc4422bec87c683/68747470733a2f2f706f7365722e707567782e6f72672f646f6e6a616e2d64656e672f6879706572662d63617362696e2f6c6963656e7365)](https://github.com/php-casbin/laravel-authz/blob/master/LICENSE)

Casbin是一个强大的、高效的开源访问控制框架，其权限管理机制支持多种访问控制模型。本项目做了Hyperf适配并自带了一个RBAC模型，使用本项目前你需要先学会如何使用Casbin。

简单使用
----

[](#简单使用)

Casbin只负责访问控制，在RBAC方案中也只是储存用户和角色之间的映射关系，身份认证、管理用户列表或角色列表应由项目自身来管理。这里有个简单的示例：[example](https://github.com/donjan-deng/hyperf-casbin-example)

### 版本定义

[](#版本定义)

本项目主版本与Casbin主版本相同，子版本和修订版本为项目独有

### 重大变更

[](#重大变更)

- 3.22适配Hyperf 3.0
- 3.21增加Redis Watcher 升级需要重新发布配置
- 3.6 升级需要重新发布配置

### 安装

[](#安装)

```
 composer require donjan-deng/hyperf-casbin

```

发布配置

```
 php bin/hyperf.php vendor:publish donjan-deng/hyperf-casbin

```

配置文件config/autoload/casbin.php

API

```
use Donjan\Casbin\Enforcer;

为用户添加权限

Enforcer::addPermissionForUser('user1', '/user', 'read');

删除一个用户的权限

Enforcer::deletePermissionForUser('user1', '/user', 'read');

获取用户所有权限

Enforcer::getPermissionsForUser('user1');

为用户添加角色

Enforcer::addRoleForUser('user1', 'role1');

为角色添加权限

Enforcer::addPermissionForUser('role1', '/user', 'edit');

获取所有角色

Enforcer::getAllRoles();

获取用户所有角色

Enforcer::getRolesForUser('user1');

根据角色获取用户

Enforcer::getUsersForRole('role1');

判断用户是否属于一个角色

Enforcer::hasRoleForUser('use1', 'role1');

删除用户角色

Enforcer::deleteRoleForUser('use1', 'role1');

删除用户所有角色

Enforcer::deleteRolesForUser('use1');

删除角色

Enforcer::deleteRole('role1');

删除权限

Enforcer::deletePermission('/user', 'read');

删除用户或者角色的所有权限

Enforcer::deletePermissionsForUser('user1');
Enforcer::deletePermissionsForUser('role1');

检查权限，返回 true or false

Enforcer::enforce("user1", "/user", "edit")
```

更多使用方法详见官方API

官方资源
----

[](#官方资源)

- [官方文档](https://casbin.org/zh/docs/overview)
- [模型编辑器](https://casbin.org/zh/editor)
- [管理API](https://casbin.org/zh/docs/management-api)
- [RBAC API](https://casbin.org/zh/docs/rbac-api)

参考库
---

[](#参考库)

- [php-casbin](https://github.com/php-casbin/php-casbin)
- [database-adapter](https://github.com/php-casbin/database-adapter)
- [laravel-authz](https://github.com/php-casbin/laravel-authz)

License
-------

[](#license)

This project is licensed under the [Apache 2.0 license](LICENSE).

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

853d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dfd742c3c43b35e19b7f48d680be2aeb42db75213e105285586b6b3f27a8b18f?d=identicon)[zds](/maintainers/zds)

---

Top Contributors

[![donjan-deng](https://avatars.githubusercontent.com/u/8256490?v=4)](https://github.com/donjan-deng "donjan-deng (4 commits)")[![mmfei](https://avatars.githubusercontent.com/u/3683362?v=4)](https://github.com/mmfei "mmfei (2 commits)")[![zds-s](https://avatars.githubusercontent.com/u/49744633?v=4)](https://github.com/zds-s "zds-s (2 commits)")[![nashgao](https://avatars.githubusercontent.com/u/9336171?v=4)](https://github.com/nashgao "nashgao (1 commits)")[![onekb](https://avatars.githubusercontent.com/u/16450084?v=4)](https://github.com/onekb "onekb (1 commits)")[![yyy1000](https://avatars.githubusercontent.com/u/69566909?v=4)](https://github.com/yyy1000 "yyy1000 (1 commits)")

---

Tags

authorizationaclpermissionrbachyperfaccess-controlabaccasbin

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/death-satan-hyperf-casbin/health.svg)

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

###  Alternatives

[casbin/casbin

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

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

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

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

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

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

webman casbin permission plugin

523.4k2](/packages/casbin-webman-permission)[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)
