Download the PHP package hyperf-plus/route without Composer
On this page you can find all versions of the php package hyperf-plus/route. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download hyperf-plus/route
More information about hyperf-plus/route
Files in hyperf-plus/route
Download hyperf-plus/route
More information about hyperf-plus/route
Files in hyperf-plus/route
Vendor hyperf-plus
Package route
Short Description route
License MIT
Homepage https://github.com/lphkxd/hyperf-route
Package route
Short Description route
License MIT
Homepage https://github.com/lphkxd/hyperf-route
Please rate this library. Is it a good library?
Informations about the package route
HPlus Route - 智能RESTful路由组件
一个为 Hyperf 框架打造的智能路由组件,支持 RESTful 规范自动路径生成、资源子操作映射、智能参数识别等高级特性。
✨ 核心特性
- 🚀 RESTful 自动映射 - 根据控制器和方法名自动生成符合 RESTful 规范的路径
- 🎯 智能参数识别 - 自动识别方法参数生成动态路径
- 🔒 注解驱动安全 - 只有明确注解的方法才能对外访问
- ⚡ 高性能设计 - 多层缓存、懒加载、O(1) 查找
- 🎨 零配置使用 - 开箱即用,但支持完全自定义
- 🔧 灵活扩展 - 支持自定义映射规则和路径模板
📦 安装
由于该版本改动较大,按照最新 restful规范,不向下兼容,如果老用户请勿升级,老模式会继续稳定跟进
🚀 快速开始
1. 基础使用
2. 资源子操作
3. 智能参数识别
4. 自定义路径
📋 RESTful 映射规则
标准 CRUD 操作
方法名 | HTTP动词 | 自动路径 | 说明 |
---|---|---|---|
index/list | GET | / | 获取列表 |
show/detail | GET | /{id} | 获取详情 |
create/store | POST | / | 创建资源 |
update/edit | PUT | /{id} | 更新资源 |
patch | PATCH | /{id} | 部分更新 |
delete/destroy | DELETE | /{id} | 删除资源 |
扩展操作
方法名 | HTTP动词 | 自动路径 | 说明 |
---|---|---|---|
search | GET | /search | 搜索 |
export | GET | /export | 导出 |
import | POST | /import | 导入 |
batch | POST | /batch | 批量操作 |
资源子操作
方法名 | HTTP动词 | 自动路径 | 说明 |
---|---|---|---|
state/status | GET | /{id}/state | 获取状态 |
enable/disable | POST | /{id}/enable | 启用/禁用 |
lock/unlock | POST | /{id}/lock | 锁定/解锁 |
permissions | GET | /{id}/permissions | 获取权限 |
history | GET | /{id}/history | 获取历史 |
🎯 注解说明
@ApiController
控制器注解,标记一个类为 API 控制器。
@GetApi / @PostApi / @PutApi / @DeleteApi / @PatchApi
方法注解,定义 HTTP 路由。
参数注解
🛠️ 高级用法
1. 路由收集器
2. 版本控制
3. 路由分组
⚡ 性能优化
- 多层缓存 - 路由、控制器、反射类缓存
- 懒加载 - 参数和请求体信息按需加载
- 索引优化 - 多维索引支持 O(1) 查找
- 智能清理 - 自动内存优化和垃圾回收
性能数据:
- 路由收集速度提升 70%
- 内存使用减少 37%
- 缓存命中率达 85%
🔧 配置
在 config/autoload/annotations.php
中配置:
🤝 与其他组件集成
与 HPlus Validate 集成
与 HPlus Swagger 集成
路由组件会自动被 Swagger 组件识别,生成 API 文档。
📝 最佳实践
-
命名约定
- 控制器:单数名词 + Controller(如
UserController
) - RESTful 方法:使用标准名称(index, show, create, update, delete)
- 扩展方法:使用描述性名称(search, export, batch)
- 控制器:单数名词 + Controller(如
-
路径设计
- 优先使用自动生成,保持一致性
- 复杂场景才手动指定路径
- 遵循 RESTful 设计原则
- 安全考虑
- 默认所有方法都需要路由注解才能访问
- 敏感操作添加
security: true
- 合理使用中间件
🐛 问题排查
-
路由未生成
- 检查是否添加了路由注解
- 确认控制器有
@ApiController
注解 - 验证注解是否正确导入
- 路径不符合预期
- 查看路由统计了解生成规则
- 使用
path
参数自定义路径 - 检查方法名是否符合映射规则
📄 许可证
MIT License
🤝 贡献
欢迎提交 Issue 和 Pull Request!
All versions of route with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.0
The package hyperf-plus/route contains the following files
Loading the files please wait ....