PHPackages                             hao1617/utils - 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. hao1617/utils

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

hao1617/utils
=============

A collection of PHP utility classes like StrHelper, NetHelper, DebugHelper, etc.

v3.1(8mo ago)017MITPHPPHP &gt;=7.2

Since Jul 31Pushed 8mo agoCompare

[ Source](https://github.com/Hao1617/hao-utils)[ Packagist](https://packagist.org/packages/hao1617/utils)[ RSS](/packages/hao1617-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (7)Used By (0)

Hao1617 Utils 工具库
=================

[](#hao1617-utils-工具库)

一个由个人维护的 PHP 原生工具类集合，适用于日常开发中常见需求，支持 Composer 加载。主要功能涵盖字符串处理、数组操作、表单验证、网络请求、文件处理、时间函数等，提升日常开发效率。

---

📦 安装方式（使用 GitHub 仓库）
--------------------

[](#-安装方式使用-github-仓库)

```
composer require hao1617/utils
```

---

📚 工具类功能说明
---------

[](#-工具类功能说明)

### 🔠 `StrHelper` - 字符串处理

[](#-strhelper---字符串处理)

- 判断前缀/后缀：`startsWith()`, `endsWith()`
- 随机字符串/UUID：`random()`, `uuid()`
- 雪花 ID 生成：`snowflakeId()`

---

### 🌐 `HttpHelper` - 网络请求

[](#-httphelper---网络请求)

- 发起 `GET`/`POST` 请求（基于 `cURL`）
- 获取客户端 IP、判断是否 HTTPS、是否 AJAX 请求等

---

### 🐞 `DebugHelper` - 调试辅助

[](#-debughelper---调试辅助)

- `dd()`：终止并打印
- `dump()`：输出内容
- `json()`：JSON 编码输出
- `log()`：写入日志文件

---

### 📦 `ArrayHelper` - 数组处理

[](#-arrayhelper---数组处理)

- 获取指定键路径：`get($array, 'a.b.c')`
- 设置嵌套值：`set($array, 'a.b.c', $value)`
- 扁平化、多维转一维等处理

---

### 📆 `DateHelper` - 日期时间处理

[](#-datehelper---日期时间处理)

- 当前时间、时间戳格式化
- 判断是否为今天、本周、本月
- 计算时间差、剩余时间等

---

### 📁 `FileHelper` - 文件处理

[](#-filehelper---文件处理)

- 判断扩展名、大小是否合法
- 保存 base64 图片为文件
- 上传文件保存、生成随机文件名
- 获取 MIME 类型等

---

### ✅ `ValidatorHelper` - 表单验证

[](#-validatorhelper---表单验证)

- 支持规则：
    - `required`
    - `string`
    - `numeric`
    - `string_or_numeric`
    - `min:x`
    - `max:x`
    - `in:a,b,c`
    - `email` 等
- 可扩展自定义验证器
- 返回结构清晰的验证结果

---

### 📡 `ResponseHelper` - 返回结构封装

[](#-responsehelper---返回结构封装)

- 统一结构返回 JSON：

```
ResponseHelper::success($data, '操作成功');
ResponseHelper::error('参数错误', 400);
```

- 返回格式：

```
{
  "code": 0,
  "message": "操作成功",
  "data": {...}
}
```

---

🧩 使用示例
------

[](#-使用示例)

```
use Gongying\Utils\StrHelper;
use Gongying\Utils\ResponseHelper;

$id = StrHelper::uuid();
return ResponseHelper::success(['id' => $id]);
```

---

🔧 要求
----

[](#-要求)

- PHP &gt;= 7.2
- 推荐搭配框架：ThinkPHP、Laravel、Symfony 等

---

📬 作者信息
------

[](#-作者信息)

- Author: Hao1617
- Email:

---

📝 License
---------

[](#-license)

MIT License

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance58

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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 ~14 days

Total

6

Last Release

267d ago

Major Versions

v1.1 → v2.02025-07-31

v2.1 → v3.02025-10-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/56282383?v=4)[Hao](/maintainers/Hao1617)[@Hao1617](https://github.com/Hao1617)

---

Top Contributors

[![Hao1617](https://avatars.githubusercontent.com/u/56282383?v=4)](https://github.com/Hao1617 "Hao1617 (18 commits)")

### Embed Badge

![Health badge](/badges/hao1617-utils/health.svg)

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

PHPackages © 2026

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