PHPackages                             xhtkyy/hyperf-tools - 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. xhtkyy/hyperf-tools

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

xhtkyy/hyperf-tools
===================

hyperf tools

v1.0.0(2y ago)55.0k1MITPHPPHP &gt;=8.0

Since Dec 31Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/xhtkyy/hyperf-tools)[ Packagist](https://packagist.org/packages/xhtkyy/hyperf-tools)[ RSS](/packages/xhtkyy-hyperf-tools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (22)Versions (16)Used By (1)

xhtkyy/hyperf-tools
===================

[](#xhtkyyhyperf-tools)

快速开始
----

[](#快速开始)

composer require xhtkyy/hyperf-tools

发布配置
----

[](#发布配置)

php bin/hyperf.php vendor:publish xhtkyy/hyperf-tools

更新
--

[](#更新)

### 20230602

[](#20230602)

- 增加服务支持Streaming模式 可参照健康检查watch方法的使用

```
$stream = new Stream();
//支持流式 多次写入
$stream->write($response)
$stream->write($response)
$stream->write($response)
...
// 记得关闭，不然还继续走 普通响应
$stream->close();
```

- Grpc Health Watch 增加 Streaming 支持

### 20230536

[](#20230536)

- 移除overwrite 增加class\_map覆盖代码，只需要配置 annotations 增加如下

```
return [
    'scan' => [
        ...
        'class_map' => [
            //需要反射增加
            \Google\Protobuf\Internal\DescriptorPool::class => BASE_PATH.'/vendor/xhtkyy/hyperf-tools/class_map/protobuf/DescriptorPool.php',
            //需要nacos支持阿里nacos的需要增加
            \Hyperf\Nacos\AbstractProvider::class => BASE_PATH.'/vendor/xhtkyy/hyperf-tools/class_map/nacos/AbstractProvider.php',
        ]
    ],
];
```

- 增加支持错误响应携带状态码 需要注意 这里将错误返回的字符串变成对象 可以加(string)$reply 转字符串

```
//使用
\Xhtkyy\HyperfTools\Grpc\Exception\GrpcError::throw("错误信息", -1);
```

基础
--

[](#基础)

### 容器

[](#容器)

- 通过注入获取（推荐） ```
    public function __construct(protected Xhtkyy\HyperfTools\App\ContainerInterface $container) {
    }
    //使用
    $this->container->get(...);
    // 或者 通过声明注入
    [Inject]
    protected Xhtkyy\HyperfTools\App\ContainerInterface
    ```
- 通过实例化(不推荐) Xhtkyy\\HyperfTools\\App\\Container
- 通过助手函数 di(class)

### 异常

[](#异常)

异常是需要规范的，这里举例了 NotFoundException（找不到资源）、InvalidArgumentException(无效参数异常) 其他自定义异常 继承 Xhtkyy\\HyperfTools\\App\\Exception\\AppException::class 即可轻松捕抓

### CURD

[](#curd)

将基础的CURD封装 继承 Xhtkyy\\HyperfTools\\CURDRepo\\CURDRepo 即可，如

```
    //继承
    class MessageRepo extends CURDRepo {
        //声明要操作的对象
        protected string $model = Message::class;
    }
    //开始使用
    class MessageController {
        #[Inject]
        protected MessageRepo $messageRepo;
        /**
         * 获取列表
         * @return array
         */
        public function getList(): array {
            $res = $this->messageRepo
                //支持关联
                ->with([
                    "app"      => function ($query) {
                        $query->selectRaw("id,app_name");
                    }
                ])
                //等比查询
                ->eqWhere("id,platform_id,app_id,channel_id,role,status,task_id") //要查询的字段 已经处理判断 请求对象中是否存在
                //范围查询
                ->betweenWhere("created_at")
                //模糊查询
                ->likeWhere("title,accept,user_name")
                //获取列表
                ->getList();
            return $res;
        }
    }
```

### 服务注册/发现

[](#服务注册发现)

#### 1、发布配置

[](#1发布配置)

```
php bin/hyperf.php vendor:publish hyperf/service-governance
php bin/hyperf.php vendor:publish xhtkyy/hyperf-tools

```

#### 2、服务注册

[](#2服务注册)

自动发现配置中server\_name配置的服务名称，在路由中对应服务名称，如以下 "grpc"

```
Router::addServer('grpc', function () {
    // 注意添加健康检查
    Router::addGroup('/grpc.health.v1.Health', function () {
        Router::post('/Check', [\Xhtkyy\HyperfTools\Grpc\Health\HealthController::class, 'check']);
        Router::post('/Watch', [\Xhtkyy\HyperfTools\Grpc\Health\HealthController::class, 'watch']);
    },[
        "register" => false //配置不注册到服务发现中心,默认注册
    ]);
    ...
});
```

#### 3、服务发现

[](#3服务发现)

使用继承 \\Xhtkyy\\HyperfTools\\GrpcClient\\BaseGrpcClient 即可完成服务自动发现 可在配置中配置发现算法 默认轮询

### 链路追踪

[](#链路追踪)

使用 Xhtkyy\\HyperfTools\\Grpc\\Middleware\\GrpcTraceMiddleware 作用于grpc服务路由即可完成 grpc链路追踪

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.7% 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 ~27 days

Recently: every ~64 days

Total

13

Last Release

909d ago

Major Versions

v0.2.3-alpha → v1.0.02023-11-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/93fc0f8369b6e970b79c37e8982f7f94773635f687c67fe37b5424f25ffe446d?d=identicon)[xhtkyy](/maintainers/xhtkyy)

---

Top Contributors

[![crayxn](https://avatars.githubusercontent.com/u/21336335?v=4)](https://github.com/crayxn "crayxn (43 commits)")[![xhtkyy](https://avatars.githubusercontent.com/u/57792697?v=4)](https://github.com/xhtkyy "xhtkyy (1 commits)")

---

Tags

phphyperf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xhtkyy-hyperf-tools/health.svg)

```
[![Health](https://phpackages.com/badges/xhtkyy-hyperf-tools/health.svg)](https://phpackages.com/packages/xhtkyy-hyperf-tools)
```

###  Alternatives

[crayoon/hyperf-grpc

hyperf grpc extend

253.7k](/packages/crayoon-hyperf-grpc)

PHPackages © 2026

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