1 Star 3 Fork 1

imi 开发组 / imi-access-control

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

imi-access-control

Latest Version Php Version Swoole Version IMI License

介绍

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

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

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

Composer

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

{
    "require": {
        "imiphp/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();

增加、设置权限

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

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

移除权限

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

判断用户是否拥有权限

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

免费技术支持

QQ群:17916227 点击加群,如有问题会有人解答和修复。

运行环境

版权信息

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

捐赠

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

MIT License Copyright (c) 2018 imiphp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

imi 框架的权限控制组件,不提供具体 API、管理界面,仅提供基础操作组件 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/imiphp/imi-access-control.git
git@gitee.com:imiphp/imi-access-control.git
imiphp
imi-access-control
imi-access-control
master

搜索帮助