arc/grants
Composer 安装命令:
composer require arc/grants
包简介
Ariadne Component Library: user and group rights management Component
关键字:
README 文档
README
A flexible component library for PHP
The Ariadne Component Library is a spinoff from the Ariadne Web Application Framework and Content Management System [ http://www.ariadne-cms.org/ ]
How it works
arc/grants is a simple and extensible system to manage access in a hierarchical system like a filesystem. At each node in the tree you can assign access grants for a specific user or group. There are no predefined grants, a grant can be any word. e.g.
\arc\grants::cd('/foo/')->setForUser('public', 'read');
This assigns the grant 'read' for the user 'public' on the path '/foo/'. This grant is automatically set for any path under '/foo/' as well. e.g:
$hasReadAccess = \arc\grants::cd('/foo/bar/')->checkForUser('public', 'read'); // returns true
You can assign multiple grants as a space-seperated string:
\arc\grants::setForUser('public', 'read add edit delete');
Grants for users do not stack. If you assign grants for a user somewhere, those will be the only grants available starting at that node. Previous grants are overwritten. If you want to revoke grants, simply set the grants again, without the grant you want revoked. To revoke all grants, set a 'marker' grant that is never checked, e.g:
\arc\grants::cd('/foo/bar/')->setForUser('public', 'none');
The grants string is a simple DSL (Domain Specific Language) that allows you to set grants that do not 'trickle down' or to set grants that only apply on child nodes:
- '=read' only assigns the grant on this node. Child nodes won't have the read grant.
- '>delete' assigns the grant only on child nodes, not on the current node.
Default user and path
You can assign a default user for the grants system to use:
\arc\grants::switchUser('admin');
Then you can assign grants and check them, without specifying the user:
\arc\grants::set('read add edit >delete'); $hasReadAccess = \arc\grants::check('read');
If you don't set a specific path with the cd() method, grants will be set and checked for the 'default' path. This is the path that is last set using \arc\grants::cd( $path ), e.g.:
\arc\grants::cd('/foo/'); \arc\grants::switchUser('admin', ['administrators','public']); $hasReadAccess = \arc\grants::check('read');
This checks the grants for user 'admin' at '/foo/'. Any subsequent calls to \arc\grants assume this is the user and path you want to use. Untill you again call either cd() or switchUser() on the \arc\grants class (statically).
Groups
If a user is member of one or more groups, you can set it like this:
\arc\grants::setForGroup('administrators', 'read add edit delete');
And check it like this:
$hasReadAccess = \arc\grants::switchUser('admin', ['administrators','public'])->check('read');
Group grants are added to any user grants previously set. If you set user grants at a node, any group grants set at parent nodes are ignored. Only group grants under that node are added to the user grants.
If you override grants for a specific group, only the later group grants are applied, but only for that specific group.
\arc\grants::cd('/') ->setForUser('mike', 'read edit') ->setForGroup('editors', 'read add edit >delete') ->cd('/foo/') ->setForGroup('editors', 'read');
Because mike has the 'edit' grant on '/', the group grants cannot remove it, so this works:
$hasEditAccess = \arc\grants::switchUser('mike', ['editors'])->cd('/foo/')->check('edit'); // => true
Because the group 'editors' grants with 'read add edit >delete' are set at the same node as Mike's personal grants, they are overruled by Mike's personal more restrictive grants, so this returns false:
$hasAddAccess = \arc\grants::switchUser('mike', ['editors'])->cd('/')->check('add'); // => false
Finally the group grants for 'editors' is overridden at '/foo/', so this also returns false:
$hasAddAccess = \arc\grants::switchUser('mike', ['editors'])->cd('/foo/')->check('add'); // => false
Listing grants
This will return a list of all user grants at a specific node. It will only return the grants set at this specific node, not a list of all currently applicable grants:
$userGrantsList = \arc\grants::cd('/foo/')->grantsForAllUsers(); $groupGrantsList = \arc\grants::grantsForAllGroups();
Both will return an array with the user or group as the key and the grants string as the value or an empty string if no grants are set.
Todo
- add support for 'owner' group, need to have a link to an owner tree, otherwise grants tree gets too large
arc/grants 适用场景与选型建议
arc/grants 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 402 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「components」 「component」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arc/grants 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arc/grants 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arc/grants 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
FSi DataSource Component
Web Font Loader gives you added control when using linked fonts via @font-face.
Priveate for SkeekS CMS
Ariadne Component Library: xml writer and parser Component
Ariadne Component Library: Cache Component
Ariadne Component Library: hierarchical configuration management Component
统计信息
- 总下载量: 402
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-06-21