PHPackages                             elisdn/yii2-hybrid-authmanager - 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. elisdn/yii2-hybrid-authmanager

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

elisdn/yii2-hybrid-authmanager
==============================

Hybrid RBAC AuthManager for Yii2 Framework.

1.0.2(4y ago)810.9k1[1 issues](https://github.com/ElisDN/yii2-hybrid-authmanager/issues)2BSD-3-ClausePHPCI failing

Since Mar 18Pushed 4y ago2 watchersCompare

[ Source](https://github.com/ElisDN/yii2-hybrid-authmanager)[ Packagist](https://packagist.org/packages/elisdn/yii2-hybrid-authmanager)[ RSS](/packages/elisdn-yii2-hybrid-authmanager/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (2)

Hybrid RBAC AuthManager for Yii2 Framework
==========================================

[](#hybrid-rbac-authmanager-for-yii2-framework)

The extension extends `yii\rbac\PhpManager` and allows to store user assignments in any storage instead of `app/rbac/assignments.php` file.

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

[](#installation)

Install with composer:

```
composer require elisdn/yii2-hybrid-authmanager
```

or add

```
"elisdn/yii2-hybrid-authmanager": "*"
```

to the require section of your `composer.json` file.

Set `authManager` component in your config:

```
'components' => [
    ...
    'authManager' => [
        'class' => 'elisdn\hybrid\AuthManager',
        'modelClass' => 'app\modules\User',
    ],
],
```

and implement `AuthRoleModelInterface` in your model class.

Usage samples
-------------

[](#usage-samples)

Storing single role in the `role` field of `user` table:

```
namespace app\models;

use elisdn\hybrid\AuthRoleModelInterface;

class User extends ActiveRecord implements IdentityInterface, AuthRoleModelInterface
{
    ...

    public static function findAuthRoleIdentity($id)
    {
        return static::findOne($id);
    }

    public static function findAuthIdsByRoleName($roleName)
    {
        return static::find()->where(['role' => $roleName])->select('id')->column();
    }

    public function getAuthRoleNames()
    {
        return (array)$this->role;
    }

    public function addAuthRoleName($roleName)
    {
        $this->updateAttributes(['role' => $this->role = $roleName]);
    }

    public function removeAuthRoleName($roleName)
    {
        $this->updateAttributes(['role' => $this->role = null]);
    }

    public function clearAuthRoleNames()
    {
        $this->updateAttributes(['role' => $this->role = null]);
    }

    ...
}
```

Storing multiple roles:

```
class User extends ActiveRecord implements IdentityInterface, AuthRoleModelInterface
{
    ...

    public function getAuthRoleNames()
    {
        return $this->roles;
    }

    public function addAuthRoleName($roleName)
    {
        $this->updateAttributes(['roles' => $this->roles = array_merge($this->roles, [$roleName])]);
    }

    public function removeAuthRoleName($roleName)
    {
        $this->updateAttributes(['roles' => $this->roles = array_diff($this->roles, [$roleName])]);
    }

    public function clearAuthRoleNames()
    {
        $this->updateAttributes(['roles' => $this->roles = []]);
    }

    ...
}
```

Or with JSON serialization:

```
class User extends ActiveRecord implements IdentityInterface, AuthRoleModelInterface
{
    ...

    public function getAuthRoleNames()
    {
        return (array)Json::decode($this->roles);
    }

    public function addAuthRoleName($roleName)
    {
        $roles = (array)Json::decode($this->roles);
        $this->roles[] = $roleName;
        $this->updateAttributes(['role' => $this->roles = Json::encode($this->roles)]);
    }

    public function removeAuthRoleName($roleName)
    {
        $roles = (array)Json::decode($this->roles);
        $this->roles = array_diff($this->roles, [$roleName])
        $this->updateAttributes(['role' => $this->roles = Json::encode($this->roles)]);
    }

    public function clearAuthRoleNames()
    {
        $this->updateAttributes(['role' => $this->roles = Json::encode([])]);
    }

    ...
}
```

### Handling role events (optional)

[](#handling-role-events-optional)

If you want to update your storage on system events just add your event handlers:

```
class User extends ActiveRecord implements IdentityInterface, AuthRoleModelInterface
{
    ...

    public static function onRenameRole(RenameRoleEvent $event)
    {
        self::updateAll(['role' => $event->newRoleName], ['role' => $event->oldRoleName]);
    }

    public static function onRemoveRole(RemoveRoleEvent $event)
    {
        self::updateAll(['role' => null], ['role' => $event->roleName]);
    }

    public static function onRemoveAll(RemoveAllEvent $event)
    {
        self::updateAll(['role' => null]);
    }

    public static function onRemoveAllAssignments(RemoveAllAssignmentsEvent $event)
    {
        self::updateAll(['role' => null]);
    }
}
```

and register the handlers:

```
'authManager' => [
    'class' => 'elisdn\hybrid\AuthManager',
    'modelClass' => 'app\models\User',
    'on renameRole' => ['app\models\User', 'onRenameRole'],
    'on removeRole' => ['app\models\User', 'onRemoveRole'],
    'on removeAll' => ['app\models\User', 'onRemoveAll'],
    'on removeAllAssignments' => ['app\models\User', 'onRemoveAllAssignments'],
],
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity65

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

Total

3

Last Release

1746d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7f81cc9da6e74906636de79dfeb497d7fc63bb44cf2839ca2730ca6bb5397b65?d=identicon)[ElisDN](/maintainers/ElisDN)

---

Top Contributors

[![ElisDN](https://avatars.githubusercontent.com/u/1673552?v=4)](https://github.com/ElisDN "ElisDN (8 commits)")

---

Tags

yii2yii 2authmanager

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/elisdn-yii2-hybrid-authmanager/health.svg)

```
[![Health](https://phpackages.com/badges/elisdn-yii2-hybrid-authmanager/health.svg)](https://phpackages.com/packages/elisdn-yii2-hybrid-authmanager)
```

###  Alternatives

[sizeg/yii2-jwt

JWT based on Icobucci

2001.0M7](/packages/sizeg-yii2-jwt)[2amigos/yii2-usuario

Highly customizable and extensible user management, authentication, and authorization Yii2 extension

298275.5k14](/packages/2amigos-yii2-usuario)[vova07/yii2-rbac-module

The RBAC module for Yii framework.

191.2k2](/packages/vova07-yii2-rbac-module)

PHPackages © 2026

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