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

ActiveLibrary

casbin/phalcon-permission
=========================

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

301PHP

Since Sep 18Pushed 5y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

phalcon-permission
==================

[](#phalcon-permission)

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

Installing
----------

[](#installing)

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

```
$ composer require
```

Configure database connection:

```
'database' => [
    'adapter' => 'mysql',
    'host' => '127.0.0.1',
    'username' => 'root',
    'password' => '',
    'dbname' => 'db-name',
    'charset' => 'utf8',
],
```

Then phalcon-permission migrations must run to create the needed tables. For this, you need to have installed the [Phalcon Dev Tools](https://github.com/phalcon/phalcon-devtools).

use [Phalcon Dev Tools](https://github.com/phalcon/phalcon-devtools) to migrate the migrations, run the command:

```
$ phalcon migration run --migrations=vendor/casbin/phalcon-permission/migrations
```

This will create a new table named `casbin_rules`.

Usage
-----

[](#usage)

### Quick start

[](#quick-start)

```
use Easyswolle\Permission\Casbin;
use Easyswolle\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:

Gets all roles:

```
$casbin->getAllRoles(); // ['writer', 'reader']
```

Gets all the authorization rules in the policy.:

```
$casbin->getPolicy();
```

Gets the roles that a user has.

```
$casbin->getRolesForUser('eve'); // ['writer']
```

Gets the users that has a role.

```
$casbin->getUsersForRole('writer'); // ['eve']
```

Determines whether a user has a role.

```
$casbin->hasRoleForUser('eve', 'writer'); // true or false
```

Adds a role for a user.

```
$casbin->addRoleForUser('eve', 'writer');
```

Adds a permission for a user or role.

```
// to user
$casbin->addPermissionForUser('eve', 'articles', 'read');
// to role
$casbin->addPermissionForUser('writer', 'articles','edit');
```

Deletes a role for a user.

```
$casbin->deleteRoleForUser('eve', 'writer');
```

Deletes all roles for a user.

```
$casbin->deleteRolesForUser('eve');
```

Deletes a role.

```
$casbin->deleteRole('writer');
```

Deletes a permission.

```
$casbin->deletePermission('articles', 'read'); // returns false if the permission does not exist (aka not affected).
```

Deletes a permission for a user or role.

```
$casbin->deletePermissionForUser('eve', 'articles', 'read');
```

Deletes permissions for a user or role.

```
// to user
$casbin->deletePermissionsForUser('eve');
// to role
$casbin->deletePermissionsForUser('writer');
```

Gets permissions for a user or role.

```
$casbin->getPermissionsForUser('eve'); // return array
```

Determines whether a user has a permission.

```
$casbin->hasPermissionForUser('eve', 'articles', 'read');  // true or false
```

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

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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