Download the PHP package lovevivi/hyperf-sensitive-words without Composer
On this page you can find all versions of the php package lovevivi/hyperf-sensitive-words. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lovevivi/hyperf-sensitive-words
More information about lovevivi/hyperf-sensitive-words
Files in lovevivi/hyperf-sensitive-words
Package hyperf-sensitive-words
Short Description 基于DFA算法的敏感词过滤组件,支持动态白名单、表情符号处理、变形文本检测等高级功能
License MIT
Homepage https://github.com/lovevivi/hyperf-sensitive-words
Informations about the package hyperf-sensitive-words
Hyperf 敏感词过滤组件
基于确定有穷自动机算法(DFA)的敏感词过滤 Hyperf 组件,高效、灵活,支持协程环境。支持表情符号处理、变形文本检测和动态白名单管理。
特性亮点
- 🚀 高性能DFA算法:基于确定有穷自动机,检测效率高
- 🏗️ 模块化架构:采用单责任原则和策略模式,代码结构清晰,易于维护和扩展
- 🎯 智能白名单系统:支持动态白名单管理,避免误判
- 🔧 灵活配置:支持多种表情符号处理策略和变形文本检测
- 💾 智能缓存:三级缓存机制,大幅提升加载速度
- 🔍 前缀索引加速:针对中等长度文本的匹配优化
- 🌐 协程友好:完全支持 Hyperf 协程环境
- 📊 详细位置信息:支持返回敏感词的精确位置和长度
- 🛡️ 异常安全:敏感词处理异常不会影响业务流程
- 🔍 模糊匹配:支持绕过技术检测,如表情符号分隔、特殊字符插入等
安装
发布配置
配置
配置文件位于 config/autoload/sensitive_words.php
:
使用方式
1. 使用服务方式
php
SensitiveHelper (主类) ├── FilterManager (过滤器管理器) │ ├── BoundaryFilter (边界检测过滤器) │ ├── LengthFilter (长度过滤器) │ └── ContextFilter (上下文过滤器) └── FuzzyMatcher (模糊匹配器)
tests/ ├── Cases/ │ ├── SensitiveHelperTest.php # SensitiveHelper 核心功能测试 │ ├── SensitiveWordsManagerTest.php # SensitiveWordsManager 管理器测试 │ └── WhitelistManagementTest.php # 白名单功能专项测试 └── AbstractTestCase.php # 测试基类 bash
运行所有测试
composer test
或者使用 PHPUnit 直接运行
./vendor/bin/phpunit
运行特定测试文件
./vendor/bin/phpunit tests/Cases/SensitiveWordsManagerTest.php
运行特定测试方法
./vendor/bin/phpunit tests/Cases/SensitiveWordsManagerTest.php::testGetAllSensitiveWords
显示详细输出
./vendor/bin/phpunit --verbose
生成代码覆盖率报告(需要安装 xdebug)
./vendor/bin/phpunit --coverage-html coverage/
### 测试统计
- **总测试数**: 52个测试 (包含架构重构后的所有功能测试)
- **总断言数**: 313个断言
- **测试覆盖**: 核心功能100%覆盖,包括模糊匹配和模块化架构
- **测试类型**: 单元测试、集成测试、性能测试、模糊匹配专项测试
- **架构测试**: 过滤器策略、依赖注入、缓存管理等模块化功能全面测试
### 添加新测试
如果你需要添加新的测试用例,请遵循以下规范:
1. **测试文件命名**: 使用 `*Test.php` 后缀
2. **测试方法命名**: 使用 `test*` 前缀,方法名要清晰描述测试内容
3. **测试分组**: 按功能模块分组,相关测试放在同一个测试类中
4. **断言使用**: 使用具体的断言方法,如 `assertStringContainsString` 而不是通用的 `assertTrue`
5. **测试数据**: 使用有意义的测试数据,包含中英文、特殊字符等各种情况
### 持续集成
项目配置了完整的测试流程,每次代码提交都会自动运行全部测试,确保代码质量。
All versions of hyperf-sensitive-words with dependencies
hyperf/framework Version ~2.2.0|~3.0.0
hyperf/di Version ~2.2.0|~3.0.0
hyperf/config Version ~2.2.0|~3.0.0
hyperf/contract Version ~2.2.0|~3.0.0
hyperf/utils Version ~2.2.0|~3.0.0
hyperf/http-server Version ~2.2.0|~3.0.0