asasi/component_ram
Composer 安装命令:
composer require asasi/component_ram
包简介
ram component
README 文档
README
调用例子
$serviceType = 调用服务(一个字符串)
$context = new ByAuthContext($serviceType);
// 设置get请求参数
$context->setGetParams($this->request->query->all());
$post = $this->request->request->all();
if ($this->context && is_array($this->context->getDecryptData())) {
$post = array_merge($post, $this->context->getDecryptData());
}
// 设置Post请求参数
$context->setPostParams($post);
// 设置UA
$context->setUa($this->request->headers->has("User-Agent") ? $this->request->headers->get("User-Agent") : "");
// 设置请求client对应的用户id
$context->setUid($this->getClientUid());
// 设置请求客户端的ip
$context->setClientIp($this->request->getClientIp());
// *** 获取 Policies Start *************************************************
// 获取用户对应角色对应的策略数组
$user = $this->userAccountService->info(['id' => $this->getClientUid()]);
if (!($user instanceof UserAccount)) {
throw new InvalidArgumentException(["%param% invalid" => ["%param%" => "client_id"]]);
}
$roles = $user->getRoles()->filter(function ($item) {
return $item instanceof AuthRole && $item->getEnable() == StatusEnum::ENABLE;
});
if ($roles->count() == 0) {
throw new ForbidException();
}
$statements = [];
foreach ($roles as $role) {
if ($role instanceof AuthRole) {
foreach ($role->getPolicies() as $policy) {
if ($policy instanceof AuthPolicy && !empty($policy->getStatements())) {
array_push($statements, $policy->getStatements());
}
}
}
}
return $statements;
// *** 获取 Policies END *************************************************
$allowStatements = [];
$denyStatements = [];
// 处理获取 禁止策略 和 允许策略 2个
foreach ($statements as $statement) {
$stArr = json_decode($statement, JSON_OBJECT_AS_ARRAY);
if (is_array($stArr)) {
foreach ($stArr as $item) {
if (array_key_exists('Effect', $item)
&& array_key_exists("Resource", $item)
&& array_key_exists("Action", $item)) {
if ($item['Effect'] === "Allow") {
array_push($allowStatements, new ByStatement($item));
} elseif ($item['Effect'] === "Deny") {
array_push($denyStatements, new ByStatement($item));
}
}
}
} else {
throw new InvalidArgumentException("invalid statements");
}
}
// 如果用户没有对应策略则禁止访问该接口
if (count($allowStatements) == 0 && count($denyStatements) == 0) {
throw new ForbidException();
}
$context->setAllowStatementArr($allowStatements);
$context->setDenyStatementArr($denyStatements);
// 最后验证 ,失败会抛出 by\component\ram\ForbidException 异常
$context->checkAuth();
asasi/component_ram 适用场景与选型建议
asasi/component_ram 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 79 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 asasi/component_ram 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 asasi/component_ram 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 79
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-25