amethyst/permission
Composer 安装命令:
composer require amethyst/permission
包简介
README 文档
README
Amethyst package.
Define permissions with an extensive customization for your data and routes.
Requirements
PHP 7.2 and later.
TODO
- Attribute Authorization
Installation
You can install it via Composer by typing the following command:
composer require amethyst/permission
The package will automatically register itself.
Usage
A simple usage looks like this
use Amethyst\Models\Permission; use Symfony\Component\Yaml\Yaml; Permission::create([ 'effect' => 'accept', 'type' => 'data', 'payload' => Yaml::dump([ 'action' => 'create', 'data' => 'foo' ]), 'agent' => '{{ agent.id }} == 1', ]);
Permissions will be automatically reloaded whenever a eloquent.saved is fired for Permission model.
Effect
The effect can be either accept or deny. Without any permissions any user is denied to perform anything. If you add both permission accept and deny both of them are applied.
For example you could set "user can see all comments" and "user cannot see this comment". At the end the user can see all comments except the one that you defined.
Type
The type of your permission indicate which class will be used to resolve your request.
It can be either data or route, but you can extend it in amethyst.permissions.permission
Agent
The agent is retrieved through the facade Illuminate\Support\Facades\Auth and the method user().
When this field is null it means that it's applied to all agents.
Agent must return a condition true or false.
If you wish to see the syntax see nicoSWD/php-rule-parser.
Before parsing with the logic parser, a twig parser comes in. The only variable passed is the agent and it is your App\Models\User. You can then use whanever logic you want to get the information you want. For example you can filter by any attributes and any relations (e.g. groups): {{ agent.groups.contains('myGroupName') ? 1 : 0 }} === 1
Payload
A payload in YAML the define the specification of your permission. For example for the permission route it can be a wildcard for the url.
Payload - Route
- name: The name of the route you wish to use, you can use wildcard
* - url: The url of the route, same like before, you can use the wildcard
*, - method: The method of the route
Some examples:
Enable endpoint /profile for each user.
use Amethyst\Models\Permission; use Symfony\Component\Yaml\Yaml; Permission::create([ 'type' => 'route', 'payload' => Yaml::dump([ 'url' => '/profile' ]) ]);
You can also use an array
use Amethyst\Models\Permission; use Symfony\Component\Yaml\Yaml; Permission::create([ 'type' => 'route', 'payload' => Yaml::dump([ 'url' => [ '/profile', '/recovery-password' ], 'method' => [ 'POST', 'GET' ] ]) ]);
Enable endpoints foo.* (foo.index, foo.create, foo.show, foo.update, foo.delete) for user id 2
use Amethyst\Models\Permission; use Symfony\Component\Yaml\Yaml; Permission::create([ 'type' => 'route', 'payload' => Yaml::dump([ 'url' => 'foo.*' ]), 'agent' => '{{ agent.id }} === 2' ]);
Payload - Data
The following example will permit the user#2 to visualize only the data named post that contains in the name foo
use Amethyst\Models\Permission; use Symfony\Component\Yaml\Yaml; Permission::create([ 'type' => 'data', 'payload' => Yaml::dump([ 'name' => [ 'post' ], 'action' => [ 'query', ], 'filter' => [ 'name ct "foo"' ] ]), 'agent' => '{{ agent.id }} === 2' ]);
List of all actions: query, create, update, remove
amethyst/permission 适用场景与选型建议
amethyst/permission 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 602 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「permission」 「amethyst」 「amethyst-permission」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 amethyst/permission 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amethyst/permission 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 amethyst/permission 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 602
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-13