PHPackages                             hanwenbo/policy - 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. hanwenbo/policy

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

hanwenbo/policy
===============

2.0.0(3y ago)25732PHP

Since Feb 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hanwenbo/policy)[ Packagist](https://packagist.org/packages/hanwenbo/policy)[ RSS](/packages/hanwenbo-policy/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

该库贡献到easyswoole仓库，大家一起维护，请移步到

policy
======

[](#policy)

用于验证、解析Policy结构和语法

安装
--

[](#安装)

```
composer require hanwenbo/policy
```

使用方法
----

[](#使用方法)

```
$policyData = [
	"Statement" => [
		[
			"Effect" => "Allow",
			"Action" => ["goods/*", "goods/list"],
		],
		[
			"Effect" => "Allow",
			"Action" => ["goods/*", "goods/list"],
		],
		[
			"Effect" => "Allow",
			"Action" => ["goods/*", "goods/list"],
		],
	],
];
$policy = new \hanwenbo\policy\Policy();
$policy->addPolicy( new \hanwenbo\policy\RequestBean\Policy( $policyData ) );
// 可以添加多组，目的：一个用户属于多个角色组的时候，或者一个角色组对应多个存储的policy的时候
$policy->addPolicy( new \hanwenbo\policy\RequestBean\Policy( $policyData ) );
$result = $policy->verify( 'goods/list' );
var_dump( $result );
```

思路说明
----

[](#思路说明)

假设是一个FaShop的商城项目

权限应该分为3个表，一个组可以拥有多个策略，为了方便开发者可以将每个模块的策略预置到数据库里，比如订单模块，商品模块，在给权限组分权限的时候，多选这些模块（策略），当验证的时候，查询出来所有的策略，扔给该库进行验证。

auth\_group 角色组

auth\_group\_policy 角色组拥有的 policy\_id 集合

auth\_policy 权限策略表

策略表里要有id、存放json的字段，json格式如下：

```
{
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "goods/*",
        "goods/list"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "goods/*",
        "goods/list"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "goods/*",
        "goods/list"
      ]
    }
  ]
}
```

TODO
----

[](#todo)

- 前端路由根据规则生成示例
- 接口应该返回给前端策略列表的示例
- 前端policy验证的库

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~454 days

Total

4

Last Release

1278d ago

Major Versions

1.1.0 → 2.0.02022-11-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff4efaf379c6fae90645ba663b1ca2e6b2ac36d026dfdd473ebab4db5a476e05?d=identicon)[hanwenbo](/maintainers/hanwenbo)

---

Top Contributors

[![hanwenbo](https://avatars.githubusercontent.com/u/5869741?v=4)](https://github.com/hanwenbo "hanwenbo (12 commits)")

### Embed Badge

![Health badge](/badges/hanwenbo-policy/health.svg)

```
[![Health](https://phpackages.com/badges/hanwenbo-policy/health.svg)](https://phpackages.com/packages/hanwenbo-policy)
```

###  Alternatives

[tzfrs/googlesitemapparser

Google Sitemap is a Sitemap standard that is supported by Ask.com, Google, YAHOO and MSN Search. This library can read in such Sitemaps and parse all urls from them.

143.3k](/packages/tzfrs-googlesitemapparser)[lrobert/gravatar

A library to make working with Gravatar in PHP easy.

101.4k](/packages/lrobert-gravatar)

PHPackages © 2026

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