PHPackages                             asasi/component\_ram - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. asasi/component\_ram

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

asasi/component\_ram
====================

ram component

v1.0.0(6y ago)079MITPHPPHP &gt;=7.2

Since Sep 25Pushed 6y ago1 watchersCompare

[ Source](https://github.com/peter-asasi/component_ram)[ Packagist](https://packagist.org/packages/asasi/component_ram)[ RSS](/packages/asasi-component-ram/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

ram
===

[](#ram)

调用例子
====

[](#调用例子)

```
$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();

```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2423d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a90846e2c3906f75af8e08d4345c6dcb8aefd87bcc4b2724f295d2609035a3a?d=identicon)[peter-asasi](/maintainers/peter-asasi)

### Embed Badge

![Health badge](/badges/asasi-component-ram/health.svg)

```
[![Health](https://phpackages.com/badges/asasi-component-ram/health.svg)](https://phpackages.com/packages/asasi-component-ram)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
