PHPackages                             mathsgod/light-rbac - 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. mathsgod/light-rbac

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

mathsgod/light-rbac
===================

A simple and lightweight role-based access control library for PHP.

v1.1.0(2mo ago)0206↑20.8%11MITPHPPHP &gt;=8.3CI passing

Since Apr 12Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/mathsgod/light-rbac)[ Packagist](https://packagist.org/packages/mathsgod/light-rbac)[ Docs](https://github.com/mathsgod/light-rbac)[ RSS](/packages/mathsgod-light-rbac/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (1)

Light RBAC
==========

[](#light-rbac)

Light RBAC is a simple and lightweight Role-Based Access Control (RBAC) library for PHP.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.3

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

[](#installation)

```
composer require mathsgod/light-rbac
```

Quick Start
-----------

[](#quick-start)

```
$rbac = new \Light\Rbac\Rbac();

$role = $rbac->addRole('admin');
$role->addPermission('post:read');
$role->addPermission('post:write');

$user = $rbac->addUser('John Doe', ['admin']);

if ($user->can('post:read')) {
    echo 'John Doe can read posts.';
}
```

---

Permissions
-----------

[](#permissions)

Permissions are strings in the format `resource:action`, e.g. `post:read`, `post:write`, `post:delete`.

The default separator is `:`. You can change it with `setPermissionSeparator()`.

```
$role = $rbac->addRole('admin');
$role->addPermission('post:read');
$role->addPermission('post:write');
```

### Wildcard Permissions

[](#wildcard-permissions)

Use `*` to grant all permissions:

```
$role->addPermission('*');

$role->can('post:read');   // true
$role->can('anything');    // true
```

Use `resource:*` to grant all actions on a specific resource:

```
$role->addPermission('post:*');

$role->can('post:read');   // true
$role->can('post:delete'); // true
$role->can('user:read');   // false
```

---

Roles
-----

[](#roles)

### Adding and Retrieving Roles

[](#adding-and-retrieving-roles)

```
$rbac->addRole('admin');
$rbac->addRole('editor');

$rbac->getRole('admin');    // returns Role object
$rbac->getRoles();          // returns all Role objects
$rbac->hasRole('admin');    // true
$rbac->removeRole('admin');
```

### Hierarchical Roles

[](#hierarchical-roles)

A parent role inherits all permissions from its child roles.

```
$admin = $rbac->addRole('admin');
$admin->addChild('editor');

$rbac->getRole('editor')->addPermission('post:read');

$admin->can('post:read'); // true — inherited from child
```

Multi-level hierarchies are supported:

```
$admin->addChild('editor');
$rbac->getRole('editor')->addChild('viewer');
$rbac->getRole('viewer')->addPermission('post:read');

$admin->can('post:read'); // true
```

Cyclic inheritance is detected and throws an `Exception`:

```
$admin->addChild('editor');
$rbac->getRole('editor')->addChild('admin'); // throws Exception
```

---

Users
-----

[](#users)

### Adding and Retrieving Users

[](#adding-and-retrieving-users)

```
$user = $rbac->addUser('John Doe', ['admin', 'editor']);

$rbac->getUser('John Doe');  // returns User object
$rbac->getUsers();           // returns all User objects
$rbac->hasUser('John Doe'); // true
$rbac->removeUser('John Doe');
```

### Checking Permissions

[](#checking-permissions)

```
$user->can('post:read');  // checks via assigned roles
```

Users can also have direct permissions independent of roles:

```
$user->addPermission('report:view');
$user->can('report:view'); // true
```

### Checking Roles

[](#checking-roles)

```
$user->hasRole('admin');  // true if directly assigned
$user->is('admin');       // true if directly assigned OR inherited via hierarchy
```

```
$admin = $rbac->addRole('admin');
$admin->addChild('editor');

$user = $rbac->addUser('John Doe', ['admin']);
$user->is('editor'); // true — inherited via hierarchy
```

### Fluent Interface

[](#fluent-interface)

`addRole()` and `removeRole()` on `User` return `static` for chaining:

```
$user->addRole('admin')->addRole('editor');
$user->removeRole('editor');
```

---

Custom Permission Separator
---------------------------

[](#custom-permission-separator)

The default separator is `:`. You can change it if needed:

```
$rbac->setPermissionSeparator('/');

$role->addPermission('post/*');
$role->can('post/read'); // true
```

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance84

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~155 days

Recently: every ~193 days

Total

6

Last Release

83d ago

PHP version history (2 changes)1.0.0PHP &gt;=8.0

v1.1.0PHP &gt;=8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18732337?v=4)[Raymond](/maintainers/mathsgod)[@mathsgod](https://github.com/mathsgod)

---

Top Contributors

[![mathsgod](https://avatars.githubusercontent.com/u/18732337?v=4)](https://github.com/mathsgod "mathsgod (43 commits)")

---

Tags

phprbacrole-based-access-control

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mathsgod-light-rbac/health.svg)

```
[![Health](https://phpackages.com/badges/mathsgod-light-rbac/health.svg)](https://phpackages.com/packages/mathsgod-light-rbac)
```

###  Alternatives

[santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

2.3k5.9M47](/packages/santigarcor-laratrust)[hosseinhezami/laravel-permission-manager

Advanced permission manager for Laravel.

353.3k](/packages/hosseinhezami-laravel-permission-manager)[smart-crowd/laravel-rbac

Laravel RBAC implementation.

151.3k](/packages/smart-crowd-laravel-rbac)

PHPackages © 2026

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