PHPackages                             zxf/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. [HTTP &amp; Networking](/categories/http)
4. /
5. zxf/utils

ActiveLibrary[HTTP &amp; Networking](/categories/http)

zxf/utils
=========

现代化的 PHP 工具包，包含强大的 DOM 操作库、数据转换和一些常用的类库、HTTP网络请求、代码压缩、通用函数集和实用工具等

v1.0.8(1mo ago)122MITPHPPHP &gt;=8.2

Since Nov 26Pushed 2w agoCompare

[ Source](https://github.com/zhaoxianfang/utils)[ Packagist](https://packagist.org/packages/zxf/utils)[ Fund](https://yoc.cn)[ RSS](/packages/zxf-utils/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (14)Used By (0)

通用工具包和通用函数集
===========

[](#通用工具包和通用函数集)

[![](https://camo.githubusercontent.com/ca2f8676f0592f8e29daaf79e70c32fb67af22cf8055deab7c7d73dbdea24125/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a78662f7574696c73)](https://camo.githubusercontent.com/ca2f8676f0592f8e29daaf79e70c32fb67af22cf8055deab7c7d73dbdea24125/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a78662f7574696c73) [![](https://camo.githubusercontent.com/1fb5d57ee2e57d58d733ad3bf189393a96e3154816834ef26db5a0d0f9461b88/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f7a68616f7869616e66616e672f7574696c732e737667)](https://camo.githubusercontent.com/1fb5d57ee2e57d58d733ad3bf189393a96e3154816834ef26db5a0d0f9461b88/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f7a68616f7869616e66616e672f7574696c732e737667) [![](https://camo.githubusercontent.com/42313b0aebced6ecc1e1e1c0df21e8d1915d313f279abd75fec326a776834b43/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f7a68616f7869616e66616e672f7574696c732e737667)](https://camo.githubusercontent.com/42313b0aebced6ecc1e1e1c0df21e8d1915d313f279abd75fec326a776834b43/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f7a68616f7869616e66616e672f7574696c732e737667) [![](https://camo.githubusercontent.com/2aa36cf4dc5fc19febcffb6615038ecb2758285f52bbd6e1caaec518f3d60a2a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f7a68616f7869616e66616e672f7574696c732e737667)](https://camo.githubusercontent.com/2aa36cf4dc5fc19febcffb6615038ecb2758285f52bbd6e1caaec518f3d60a2a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f7a68616f7869616e66616e672f7574696c732e737667) [![](https://camo.githubusercontent.com/801d0e57bd762ab0acc7cf123cd08bed8171e0663a637a1b94880659ff721ca4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7a68616f7869616e66616e672f7574696c732e737667)](https://camo.githubusercontent.com/801d0e57bd762ab0acc7cf123cd08bed8171e0663a637a1b94880659ff721ca4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7a68616f7869616e66616e672f7574696c732e737667) [![](https://camo.githubusercontent.com/e25fe3f6ce33a61866518e6e9ce861230b8800b9bb87869cc91a8090b46e1c07/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f7a68616f7869616e66616e672f7574696c732e737667)](https://camo.githubusercontent.com/e25fe3f6ce33a61866518e6e9ce861230b8800b9bb87869cc91a8090b46e1c07/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f7a68616f7869616e66616e672f7574696c732e737667)

基于 PHP 8.2+ 的现代化工具库，严格类型检查，丰富的实用类和函数。

📦 安装
----

[](#-安装)

```
composer require zxf/utils
```

### 配置

[](#配置)

```
# Laravel 中发布配置文件
php artisan vendor:publish --tag=utils-config
```

核心特性
----

[](#核心特性)

- **PHP 8.2+ 严格类型**：所有文件均启用 `declare(strict_types=1)`
- **现代化语法**：充分利用 `match`、联合类型、`readonly` 类、`never` 返回类型等
- **零全局副作用**：无隐式时区设置、无意外输出
- **丰富的辅助函数**：50+ 全局便捷函数

常用函数
----

[](#常用函数)

```
// 极速并发 UUID 生成器
uuid(): string

// 数据获取与设置
u_data_get($target, 'user.name', 'default');
u_data_set($array, 'user.name', 'John');

// 条件执行
u_when($value, fn ($v) => $v * 2);
u_unless($value, fn () => 'empty');

// 结果封装
$result = u_ok($data);   // Result::ok()
$result = u_err('Error'); // Result::err()

// 性能测试
u_benchmark(fn () => heavyOperation());

// 重试机制
u_retry(fn () => fetchData(), times: 3, sleep: 100);

// 速率限制
u_limiter('api', 60, 60)->attempt();

// 数据大小格式化
u_format_size(1536); // "1.5 KB"
u_parse_size('2.5GB'); // 2684354560
```

新增工具类
-----

[](#新增工具类)

类说明`Support\Pipeline`数据流水线处理，支持异常捕获、条件执行`Support\Result`成功/失败结果封装，链式操作`Support\Retry`重试机制，支持指数退避、抖动策略`Support\Benchmark`性能基准测试，支持多次平均和对比`Support\Once`确保回调只执行一次`Support\Fluent`流式接口构建器基类`Support\EnumHelper`枚举工具类（names/values/random/options）`Support\RateLimiter`内存速率限制器`Support\Condition`声明式条件执行构建器`Support\Defer`Go 风格延迟执行（LIFO）`Support\Sanitizer`输入数据清理与规范化`Net\Url`URL 解析与链式构建`Net\Domain`域名验证、Punycode、DNS/WHOIS 查询`Convert\DataSize`数据大小转换（B/KB/MB/GB/TB/PB）`Convert\Number`数字格式化、中文大写、缩写、序数`Convert\Color`颜色空间转换（HEX/RGB/HSL/HSV/CMYK）`Convert\Unit`单位换算工具`Security\XssCleaner`XSS 清理工具`Security\Password`密码哈希、强度检测、安全生成、HIBP 检测`Security\Hash`通用哈希工具（MD5/SHA/HMAC/文件哈希/CRC32）`Support\Arr`静态数组工具（点符号路径、扁平化、分组、笛卡尔积）`Convert\Json`JSON 编码解码、路径查询、合并、文件读写`Files\CSV`CSV 读写、流式处理、编码转换、JSON 互转`Text\Template`轻量级模板引擎（变量、条件、循环、过滤器）`Date\CronExpression`Cron 表达式解析与下次执行时间计算`Cache\MemoryCache`带 TTL 和标签的内存缓存，支持 remember 和原子递增`Files\Path`跨平台路径处理（拼接、规范化、相对路径、扩展名）`Data\Random`安全随机数据生成（密码、UUID v4、颜色、假数据）`Security\Token`HMAC 签名 Token 生成与验证（类似简化版 JWT）`Support\Timer`纳秒级计时器与超时控制，支持高精度睡眠`Text\Diff`文本差异比较（LCS 算法），支持统一差异和 HTML 高亮`Files\Archive`ZIP 压缩解压，支持链式 API、密码保护和目录递归`Support\Locker`基于 flock 的进程级互斥锁，支持超时和同步回调`Support\Event`轻量级事件分发器，支持通配符和一次性监听器`Data\Version`语义化版本号（SemVer）解析、比较和约束匹配现有模块
----

[](#现有模块)

### BarCode 一维条形码

[](#barcode-一维条形码)

[一维条形码文档](src/BarCode/README.md)

### QrCode 二维码

[](#qrcode-二维码)

[二维码文档](src/QrCode/README.md)

### Xml 转换处理

[](#xml-转换处理)

[查看文档](src/Xml/readme.md)

### Minify 代码压缩

[](#minify-代码压缩)

[查看文档](src/Minify/README.md)

### Image 图片处理

[](#image-图片处理)

### Http 网络请求

[](#http-网络请求)

### Crypto 加密解密

[](#crypto-加密解密)

### Data 数据转换、Tree 树形结构、大数计算

[](#data-数据转换tree-树形结构大数计算)

### Date 日期时间工具

[](#date-日期时间工具)

### Validate 数据验证

[](#validate-数据验证)

### Array 增强数组操作

[](#array-增强数组操作)

### Str 字符串处理

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

更多
--

[](#更多)

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance94

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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

Recently: every ~8 days

Total

13

Last Release

42d ago

Major Versions

v0.0.4 → v1.0.02026-02-11

PHP version history (2 changes)v0.0.1PHP ^8.1

v0.0.4PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1578312?v=4)[Felix Zhu](/maintainers/zxf)[@zxf](https://github.com/zxf)

---

Top Contributors

[![zhaoxianfang](https://avatars.githubusercontent.com/u/28860960?v=4)](https://github.com/zhaoxianfang "zhaoxianfang (2 commits)")

---

Tags

aesarraycryptocurlecchttpimagickrsautilhttpphpqrcodexmlarraycurlcsscryptoimagehtmldomtoolfileoauthtreebarcodeutiltoolsutilsHTML ParserXpathphp8.3web-scraperphp82xml-parserphp84

### Embed Badge

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

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

###  Alternatives

[php-curl-class/php-curl-class

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

3.4k9.9M377](/packages/php-curl-class-php-curl-class)[jbzoo/utils

Collection of PHP functions, mini classes and snippets for everyday developer's routine life.

8311.6M36](/packages/jbzoo-utils)[duzun/hquery

An extremely fast web scraper that parses megabytes of HTML in a blink of an eye. No dependencies. PHP5+

362167.6k5](/packages/duzun-hquery)[vinelab/http

An http library developed for the laravel framework. aliases itself as HttpClient

59302.6k11](/packages/vinelab-http)[svyatov/curlwrapper

Flexible wrapper class for PHP cURL extension

55108.1k3](/packages/svyatov-curlwrapper)[openapi/openapi-sdk

Minimal and agnostic PHP SDK for Openapi® (https://openapi.com)

171.4k1](/packages/openapi-openapi-sdk)

PHPackages © 2026

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