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

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

casbin/easyswoole-permission
============================

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

v1.6.0(4y ago)9138↓50%6Apache-2.0PHPPHP ^7.2

Since Mar 17Pushed 4y ago3 watchersCompare

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

READMEChangelog (8)Dependencies (5)Versions (9)Used By (0)

easyswoole-permission
=====================

[](#easyswoole-permission)

 **easyswoole-permission is an authorization library for the easyswoole framework.**

 [ ![Build Status](https://github.com/php-casbin/easyswoole-permission/workflows/build/badge.svg?branch=master) ](https://github.com/php-casbin/easyswoole-permission/actions) [ ![Coverage Status](https://camo.githubusercontent.com/494bc3256c1a26f023ab9a023bccb9f0f14b7a9e57707ce5018dd6c6c2dc9e84/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7068702d63617362696e2f6561737973776f6f6c652d7065726d697373696f6e2f62616467652e737667) ](https://coveralls.io/github/php-casbin/easyswoole-permission) [ ![Latest Stable Version](https://camo.githubusercontent.com/c5dc4d01a07f5d4b0a1a5e3b81602397e5420930e20fd7ca4f2448e7f816e9ab/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f6561737973776f6f6c652d7065726d697373696f6e2f762f737461626c65) ](https://packagist.org/packages/casbin/easyswoole-permission) [ ![Total Downloads](https://camo.githubusercontent.com/b6acb6c1bbc3baafe07bb1ece9db48011f164ed7b37a5846dfe673c03996df9b/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f6561737973776f6f6c652d7065726d697373696f6e2f646f776e6c6f616473) ](https://packagist.org/packages/casbin/easyswoole-permission) [ ![License](https://camo.githubusercontent.com/be3908ff871bc06da7a53c0e28605b93783a614a6da1d38eaf09a933979ab7c2/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f6561737973776f6f6c652d7065726d697373696f6e2f6c6963656e7365) ](https://packagist.org/packages/casbin/easyswoole-permissionz)

[Chinese Version](https://github.com/php-casbin/easyswoole-permission/blob/master/README_CN.md)

It's based on [Casbin](https://github.com/php-casbin/php-casbin), an authorization library that supports access control models like `ACL`, `RBAC`, `ABAC`.

All you need to learn to use `Casbin` first.

- [Installation](#installation)
- [Usage](#usage)

    - [Database settings](#database-settings)
    - [Create corresponding data table](#create-corresponding-data-table)

    - [Quick start](#quick-start)
    - [Using Enforcer Api](#using-enforcer-api)
- [Thinks](#thinks)
- [License](#license)

Installation
------------

[](#installation)

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

```
$ composer install
```

Or in the root directory of your easyswoole application, you can use the following composer command to install this package directly .

```
$ composer require casbin/easyswoole-permission
```

Usage
-----

[](#usage)

### Database settings

[](#database-settings)

add mysql configuration to `dev.php`:

```
/*################ MYSQL CONFIG ##################*/

'MYSQL'  => [
    'host'          => '127.0.0.1',
    'port'          => 3306,
    'user'          => 'root',
    'password'      => 'root',
    'database'      => 'easyswoole',
    'timeout'       => 5,
    'charset'       => 'utf8mb4',
]
```

add mysql configuration to `EasySwooleEvent.php`:

```
use EasySwoole\ORM\Db\Connection;
use EasySwoole\ORM\DbManager;

public static function initialize()
{
  ...
  $config = new \EasySwoole\ORM\Db\Config(Config::getInstance()->getConf('MYSQL'));
  DbManager::getInstance()->addConnection(new Connection($config));
}
```

### Create corresponding data table

[](#create-corresponding-data-table)

Before using it, you need to create a table named `casbin_rules` for Casbin to store the policy.

Take mysql as an example:

```
CREATE TABLE  if not exists  `casbin_rules` (
  `id` BigInt(20) unsigned NOT NULL AUTO_INCREMENT,
  `ptype` varchar(255) DEFAULT NULL,
  `v0` varchar(255) DEFAULT NULL,
  `v1` varchar(255) DEFAULT NULL,
  `v2` varchar(255) DEFAULT NULL,
  `v3` varchar(255) DEFAULT NULL,
  `v4` varchar(255) DEFAULT NULL,
  `v5` varchar(255) DEFAULT NULL,
  `create_time` timestamp NULL DEFAULT NULL,
  `update_time` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4;
```

### Quick start

[](#quick-start)

Then you can start like this:

```
use EasySwoole\Permission\Casbin;
use EasySwoole\Permission\Config;

$config = new Config();
$casbin = new Casbin($config);

// 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:

First create an instance of the enforcer class, and the following operations are based on this instance:

```
$config = new Config();
$casbin = new Casbin($config);
$enforcer = $casbin->enforcer();
```

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.

Thinks
------

[](#thinks)

[Casbin](https://github.com/php-casbin/php-casbin) in Easyswoole. You can find the full documentation of Casbin [on the website](https://casbin.org/).

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity53

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

Every ~35 days

Recently: every ~58 days

Total

8

Last Release

1677d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/35752209?v=4)[Jon](/maintainers/leeqvip)[@leeqvip](https://github.com/leeqvip)

---

Top Contributors

[![basakest](https://avatars.githubusercontent.com/u/47746206?v=4)](https://github.com/basakest "basakest (13 commits)")[![leeqvip](https://avatars.githubusercontent.com/u/35752209?v=4)](https://github.com/leeqvip "leeqvip (12 commits)")[![hsluoyz](https://avatars.githubusercontent.com/u/3787410?v=4)](https://github.com/hsluoyz "hsluoyz (6 commits)")[![Player626](https://avatars.githubusercontent.com/u/44792981?v=4)](https://github.com/Player626 "Player626 (3 commits)")[![kang8](https://avatars.githubusercontent.com/u/36906329?v=4)](https://github.com/kang8 "kang8 (2 commits)")[![hlhill](https://avatars.githubusercontent.com/u/29574366?v=4)](https://github.com/hlhill "hlhill (1 commits)")

### Embed Badge

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

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

###  Alternatives

[casbin/laravel-authz

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

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

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

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

webman casbin permission plugin

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

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

453.1k](/packages/casbin-codeigniter-permission)

PHPackages © 2026

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