PHPackages                             casbin/hyperf-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. casbin/hyperf-permission

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

casbin/hyperf-permission
========================

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

v1.0.0(2y ago)1822Apache-2.0PHPPHP &gt;=7.2

Since Aug 28Pushed 2y ago3 watchersCompare

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

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

 hyperf-permission
===================

[](#-hyperf-permission-)

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

Installing
----------

[](#installing)

Require this package in the `composer.json` of your Hyperf project. This will download the package.

```
$ composer require casbin/hyperf-permission -vvv
```

To publish the config, run the vendor publish command:

```
$ php bin/hyperf.php vendor:publish casbin/hyperf-permission
```

This will create a new model config file named `config/autoload/casbin-rbac-model.conf`, a new permission config file named `config/autoload/permission.php` and new migrate file named `2020_07_22_213202_create_rules_table.php`.

To migrate the migrations, run the migrate command:

```
$ php bin/hyperf.php migrate
```

This will create a new table named `rules` .

Usage
-----

[](#usage)

### Quick start

[](#quick-start)

Once installed you can do stuff like this:

```
use Hyperf\Permission\Casbin;

$casbin = new Casbin();

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

You can check if a user has a permission like this:

```
// to check if a user has permission
if ($casbin->enforce('eve', 'articles', 'edit')) {
  // permit eve to edit articles
} else {
  // deny the request, show an error
}
```

### Using Enforcer Api

[](#using-enforcer-api)

It provides a very rich api to facilitate various operations on the Policy:

Gets all roles:

```
Enforcer::getAllRoles(); // ['writer', 'reader']
```

Gets all the authorization rules in the policy.:

```
Enforcer::getPolicy();
```

Gets the roles that a user has.

```
Enforcer::getRolesForUser('eve'); // ['writer']
```

Gets the users that has a role.

```
Enforcer::getUsersForRole('writer'); // ['eve']
```

Determines whether a user has a role.

```
Enforcer::hasRoleForUser('eve', 'writer'); // true or false
```

Adds a role for a user.

```
Enforcer::addRoleForUser('eve', 'writer');
```

Adds a permission for a user or role.

```
// to user
Enforcer::addPermissionForUser('eve', 'articles', 'read');
// to role
Enforcer::addPermissionForUser('writer', 'articles','edit');
```

Deletes a role for a user.

```
Enforcer::deleteRoleForUser('eve', 'writer');
```

Deletes all roles for a user.

```
Enforcer::deleteRolesForUser('eve');
```

Deletes a role.

```
Enforcer::deleteRole('writer');
```

Deletes a permission.

```
Enforcer::deletePermission('articles', 'read'); // returns false if the permission does not exist (aka not affected).
```

Deletes a permission for a user or role.

```
Enforcer::deletePermissionForUser('eve', 'articles', 'read');
```

Deletes permissions for a user or role.

```
// to user
Enforcer::deletePermissionsForUser('eve');
// to role
Enforcer::deletePermissionsForUser('writer');
```

Gets permissions for a user or role.

```
Enforcer::getPermissionsForUser('eve'); // return array
```

Determines whether a user has a permission.

```
Enforcer::hasPermissionForUser('eve', 'articles', 'read');  // true or false
```

See [Casbin API](https://casbin.org/docs/en/management-api) for more APIs.

Contributing
------------

[](#contributing)

You can contribute in one of three ways:

1. File bug reports using the \[[issue tracker](https://github.com/yi17310320725/hyperf-authz/issues)\]().
2. Answer questions or fix bugs on the \[[issue tracker](https://github.com/yi17310320725/hyperf-authz/issues)\]().
3. Contribute new features or update the wiki.

*The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.*

License
-------

[](#license)

Apache-2.0

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

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

994d ago

### Community

Maintainers

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

---

Top Contributors

[![kang8](https://avatars.githubusercontent.com/u/36906329?v=4)](https://github.com/kang8 "kang8 (4 commits)")[![leeqvip](https://avatars.githubusercontent.com/u/35752209?v=4)](https://github.com/leeqvip "leeqvip (4 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/casbin-hyperf-permission/health.svg)](https://phpackages.com/packages/casbin-hyperf-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/think-authz

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

27918.5k6](/packages/casbin-think-authz)[hyperf-ext/jwt

The Hyperf JWT package.

53134.9k2](/packages/hyperf-ext-jwt)[hyperf-ext/auth

The Hyperf Auth package.

2376.2k3](/packages/hyperf-ext-auth)[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)

PHPackages © 2026

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