PHPackages                             ftlh2005/imi-access-control-expand - 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. ftlh2005/imi-access-control-expand

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

ftlh2005/imi-access-control-expand
==================================

imi 框架的权限控制组件 扩展版

v2.0.2(4y ago)034MITPHPPHP &gt;=7.4.0

Since Apr 22Pushed 4y agoCompare

[ Source](https://github.com/ftlh2005/imi-access-control-expand)[ Packagist](https://packagist.org/packages/ftlh2005/imi-access-control-expand)[ RSS](/packages/ftlh2005-imi-access-control-expand/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)DependenciesVersions (9)Used By (0)

imi-access-control-expand
=========================

[](#imi-access-control-expand)

[![Latest Version](https://camo.githubusercontent.com/85b4c42656826e762ea96dbf3449a3c5ad1fa0a6aeb338a438c9bc9ff8f78b78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d697068702f696d692d6163636573732d636f6e74726f6c2e737667)](https://packagist.org/packages/imiphp/imi-access-control)[![Php Version](https://camo.githubusercontent.com/315f5c30e505b9ccc4178451bbd34c2ba5d281d1fa3267304053ed19ab634125/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e312d627269676874677265656e2e737667)](https://secure.php.net/)[![Swoole Version](https://camo.githubusercontent.com/f077644cadc3b88104d75a54818d0e1462f910dc6d6dfd9939ea295fb11b4e2b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73776f6f6c652d2533453d342e312e302d627269676874677265656e2e737667)](https://github.com/swoole/swoole-src)[![IMI License](https://camo.githubusercontent.com/571b0b4dc74d08801124791056468cb081fc1ce3f5dd81e978b258d9563568ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f696d697068702f696d692d6163636573732d636f6e74726f6c2e737667)](https://github.com/imiphp/imi-access-control/blob/master/LICENSE)

介绍
--

[](#介绍)

该项目为imi-access-control扩展版，增加了title,icon 字段方便做成权限菜单

imi 框架的权限控制组件，不提供具体 API、管理界面，仅提供基础操作组件。

本组件中支持：角色关联操作，用户关联角色，用于关联操作。

用户除了角色赋予的操作权限以外，还可以单独赋予操作权限。

Composer
--------

[](#composer)

本项目可以使用composer安装，遵循psr-4自动加载规则，在你的 `composer.json` 中加入下面的内容:

```
{
    "require": {
        "ftlh2005/imi-access-control": "~1.0"
    }
}
```

然后执行 `composer update` 安装。

使用
--

[](#使用)

在项目 `config/config.php` 中配置：

```
[
    'components'    =>  [
        // 引入本组件
        'AccessControl'    =>  'Imi\AC',
    ],
]
```

### 操作权限

[](#操作权限)

#### 创建操作权限

[](#创建操作权限)

```
use Imi\AC\AccessControl\Operation;

Operation::create('权限名称');

// 权限代码不传或为null，则和权限名称相同，不可重复
Operation::create('权限名称', '权限代码');

// 指定父级ID、排序索引
Operation::create('权限名称', '权限代码', $parentId, $index, '介绍');
```

### 角色

[](#角色)

#### 创建角色

[](#创建角色)

```
use Imi\AC\AccessControl\Role;

// 与 Operation::create 一样，不多做说明了
$role = Role::create('权限名称', '权限代码', '介绍');
```

#### 获取角色信息

[](#获取角色信息)

```
// 支持ID、Code两种模式
$role = new Role('权限ID');
$role = new Role('权限代码', 'code');
$roleInfo = $role->getRoleInfo(); // $roleInfo->id/code/name/description
```

#### 获取角色操作权限

[](#获取角色操作权限)

```
// 数组，成员为 \Imi\AC\Model\Operation 类型
$operations = $role->getOperations();

// 树形结构，成员为 \Imi\AC\Model\Filter\OperationTreeItem 类型，$item->children 为其下一级角色，同样为 \Imi\AC\Model\Filter\OperationTreeItem 类型
$operationTree = $role->getOperationTree();
```

#### 增加、设置权限

[](#增加设置权限)

```
$role->addOperations('code1', 'code2'); // 只在当前基础上增加这两个权限

$role->setOperations('code1', 'code2'); // 将角色权限设置为仅有这两个权限
```

#### 移除权限

[](#移除权限)

```
$role->removeOperations('code1', 'code2');
```

#### 判断角色是否拥有权限

[](#判断角色是否拥有权限)

```
$result = $role->hasOperations('code1', 'code2');
```

### 用户

[](#用户)

#### 获取该用户所有角色

[](#获取该用户所有角色)

```
use Imi\AC\AccessControl\Member;

$memberId = 1;
$member = new Member(1);

$roles = $member->getRoles();
```

#### 增加、设置角色

[](#增加设置角色)

```
$member->addRoles('code1', 'code2'); // 只在当前基础上增加这两个角色

$member->setRoles('code1', 'code2'); // 将用户角色设置为仅有这两个角色
```

#### 移除角色

[](#移除角色)

```
$member->removeRoles('code1', 'code2');
```

#### 判断用户是否拥有角色

[](#判断用户是否拥有角色)

```
$result = $member->hasRoles('code1', 'code2');
```

#### 获取用户操作权限

[](#获取用户操作权限)

```
// 数组，成员为 \Imi\AC\Model\Operation 类型
$operations = $member->getOperations();

// 树形结构，成员为 \Imi\AC\Model\Filter\OperationTreeItem 类型，$item->children 为其下一级角色，同样为 \Imi\AC\Model\Filter\OperationTreeItem 类型
$operationTree = $member->getOperationTree();
```

#### 增加、设置权限

[](#增加设置权限-1)

```
$member->addOperations('code1', 'code2'); // 只在当前基础上增加这两个权限

$member->setOperations('code1', 'code2'); // 将角色权限设置为仅有这两个权限
```

#### 移除权限

[](#移除权限-1)

```
$member->removeOperations('code1', 'code2');
```

#### 判断用户是否拥有权限

[](#判断用户是否拥有权限)

```
$result = $member->hasOperations('code1', 'code2');
```

免费技术支持
------

[](#免费技术支持)

QQ群：17916227 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq)，如有问题会有人解答和修复。

运行环境
----

[](#运行环境)

- [PHP](https://php.net/) &gt;= 7.1
- [Composer](https://getcomposer.org/)
- [Swoole](https://www.swoole.com/) &gt;= 4.1.0

版权信息
----

[](#版权信息)

`imi-access-control` 遵循 MIT 开源协议发布，并提供免费使用。

捐赠
--

[](#捐赠)

[![](https://raw.githubusercontent.com/imiphp/imi-access-control/master/res/pay.png)](https://raw.githubusercontent.com/imiphp/imi-access-control/master/res/pay.png)

开源不求盈利，多少都是心意，生活不易，随缘随缘……

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~126 days

Recently: every ~116 days

Total

8

Last Release

1690d ago

Major Versions

v1.0.5 → v2.0.22021-09-25

### Community

Maintainers

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

---

Top Contributors

[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (12 commits)")[![ftlh2005](https://avatars.githubusercontent.com/u/6311331?v=4)](https://github.com/ftlh2005 "ftlh2005 (6 commits)")

### Embed Badge

![Health badge](/badges/ftlh2005-imi-access-control-expand/health.svg)

```
[![Health](https://phpackages.com/badges/ftlh2005-imi-access-control-expand/health.svg)](https://phpackages.com/packages/ftlh2005-imi-access-control-expand)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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