yiisoft/rbac-rules-container
Composer 安装命令:
composer require yiisoft/rbac-rules-container
包简介
RBAC rules container based on "yiisoft/factory"
关键字:
README 文档
README
Yii RBAC Rules Container
This package is a factory for creating Yii RBAC (Role-Based Access Control) rules. It provides rules container based on Yii Factory and uses Yii Definitions syntax. RBAC manager accepts rule as a name and parameters and is unaware of its creation by design, delegating creation to rules container keeping responsibilities separation.
Requirements
- PHP 8.1 or higher.
Installation
The package could be installed with Composer:
composer require yiisoft/rbac-rules-container
General usage
Direct interaction with rules container
use Psr\Container\ContainerInterface; use Yiisoft\Rbac\Item; use Yiisoft\Rbac\RuleInterface; use Yiisoft\Rbac\Rules\Container\RulesContainer; /** * Checks if user ID matches `authorID` passed via parameters. */ final class AuthorRule implements RuleInterface { public function execute(string $userId, Item $item, array $parameters = []): bool { return $parameters['authorID'] === $userId; } } $rulesContainer = new RulesContainer(new MyContainer()); $rule = $rulesContainer->create(AuthorRule::class);
MyContaineris a container for resolving dependencies and must be an instance ofPsr\Container\ContainerInterface. Yii Dependency Injection implementation also can be used.- You can optionally set definitions and disable their validation if needed.
Basically, the arguments are the same as in Yii Factory. Please refer to its docs for more details.
Rules are created only once, then cached and reused for repeated calls.
$rule = $rulesContainer->create(AuthorRule::class); // Returned from cache
Using Yii config
use Yiisoft\Di\Container; use Yiisoft\Di\ContainerConfig; use Yiisoft\Rbac\RuleFactoryInterface; use Yiisoft\Rbac\Rules\Container\RulesContainer; // Need to be moved to separate files accordingly $params = [ 'yiisoft/rbac-rules-container' => [ 'rules' => ['author' => AuthorRule::class], 'validate' => false, ], ]; $config = [ RuleFactoryInterface::class => [ 'class' => RulesContainer::class, '__construct()' => [ 'definitions' => $params['yiisoft/rbac-rules-container']['rules'], 'validate' => $params['yiisoft/rbac-rules-container']['validate'], ], ], ]; $containerConfig = ContainerConfig::create()->withDefinitions($config); $container = new Container($containerConfig); $rulesContainer = $container->get(RuleFactoryInterface::class); $rule = $rulesContainer->create('author');
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii RBAC Rules Container is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.
Support the project
Follow updates
yiisoft/rbac-rules-container 适用场景与选型建议
yiisoft/rbac-rules-container 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66.01k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2022 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「container」 「rules」 「factory」 「yii」 「rbac」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yiisoft/rbac-rules-container 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yiisoft/rbac-rules-container 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yiisoft/rbac-rules-container 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing object factory for PHP
Testing object factory for PHP
Magento 2 module which adds support for Speculation Rules API for instant page loads.
The coding standard applying to all Youdot PHP projects, based on Doctrine set of PHPCS rules, with additional checks.
Laravel 5 Model Factory Generator.
Business rules engine tools.
统计信息
- 总下载量: 66.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 26
- 依赖项目数: 5
- 推荐数: 1
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2022-02-12