Expand description
SZ-Rust Core — 主框架包
对标 ThinkPHP 8 的 Rust Web 框架核心,基于 axum 0.8 + SZ-ORM。
§模块结构
所有模块均已实现并通过测试。addons 重导出 sz-rust-addons-loader,
macros 重导出 sz-rust-macros 的过程宏。
| 模块 | 对齐 PHP | 状态 |
|---|---|---|
controller | app\SzController / app\BaseController | ✅ |
model | think\Model | ✅ |
schema_cache | think\db\Fetch 字段缓存(SchemaCache + TableSchema + ColumnDefinition) | ✅ |
relation | think\Model 关联关系(HasMany/BelongsTo/HasOne/BelongsToMany/Morph) | ✅ |
request | $this->request->post/get | ✅ |
response | renderJson/renderSuccess/renderError | ✅ |
middleware | CORS/Auth/Log/RateLimit/Trace | ✅ |
guard | NestJS Guard + Spring Security(sz-rust 自研) | ✅ |
hooks | think-orm Model 钩子(HookDispatcher 16 事件) | ✅ |
multi_app | auto_multi_app | ✅ |
health | 健康检查端点(K8s liveness/readiness) | ✅ |
static_files | 静态文件路由(tower-http::ServeDir) | ✅ |
error_handler | 404/500 标准化 JSON 响应 | ✅ |
h2 | HTTP/2 + TLS(think-swoole SSL) | ✅ |
routing | 三层路由机制(属性宏/配置式/约定式) | ✅ |
addons | addons/ 插件 | ✅ 重导出 sz-rust-addons-loader |
router | with_route | ✅ |
container | app() 容器 | ✅ |
error | BaseException | ✅ |
macros | compact() | ✅ 重导出 sz-rust-macros |
config | config/app.php / database.php | ✅ |
log | think-logger | ✅ |
server | think-swoole / think-worker 启动入口 | ✅ |
validate | think\Validate 数据验证器 | ✅ |
upload | think\File + think\file\UploadedFile 文件上传 | ✅ |
cache | think\facade\Cache 缓存 facade | ✅ |
session | think\facade\Session 会话管理(SessionStore trait + MemorySessionStore) | ✅ |
cookie | think\Cookie Cookie 管理(CookieJar + CookieOptions) | ✅ |
event | think\Event 事件系统(Listener/Subscriber/Observer) | ✅ |
env | think\facade\Env 环境变量管理 | ✅ |
i18n | think\facade\Lang 多语言国际化 | ✅ |
mail | think\facade\Mail 邮件抽象(Mailer trait + MemoryMailer) | ✅ |
notify | think\facade\Notify 通知抽象(Notifier trait + MemoryNotifier + SlackNotifier) | ✅ |
oauth | Laravel Socialite OAuth2 客户端(OAuth2Provider trait + GenericOAuth2Provider) | ✅ |
pay | yansongda/pay 支付聚合(PayProvider trait + MemoryPayProvider + PayHttpTransport) | ✅ |
migration_history | think migrate 迁移历史表(多方言 DDL + CRUD SQL 生成) | ✅ |
api_version | API 版本管理(URL/Header/Query 多策略协商) | ✅ |
cache_warmer | 缓存预热管道(部署/启动时预热,串行/并行+超时控制) | ✅ |
debug_page | Whoops-style 调试页(开发环境 HTML + 生产环境简洁页) | ✅ |
openapi | OpenAPI 3.0.3 规范构建器 + Swagger UI / Redoc 渲染 | ✅ |
qr_code | endroid/qr-code 二维码生成(PNG/SVG/矩阵) | ✅ |
wechat | overtrue/wechat / EasyWeChat 微信 SDK(公众号/小程序/开放平台/企业微信) | ✅ |
gateway | GatewayWorker\Gateway WebSocket 客户端管理(Gateway API 抽象 + GatewayTransport trait + MemoryGatewayTransport) | ✅ |
Re-exports§
pub use sz_rust_middleware_facade as middleware;pub use sz_rust_orm_facade as orm;pub use sz_rust_http_facade as http;pub use sz_rust_cache_facade as cache;pub use sz_rust_state_facade as state;pub use sz_rust_infra_facade as infra;pub use sz_rust_auth_facade as auth;
Modules§
- addons
- 插件加载模块 — 重导出
sz-rust-addons-loader - api_
version - API 版本管理 — URL/Header/Query 多策略
- cache_
warmer - 缓存预热机制(Cache Warmer)
- config
- 配置系统 — YAML 加载 + 环境变量覆盖 + 默认值
- container
- App 容器 — DB/Cache/Log 单例 + DI 服务容器
- controller
- 控制器模块 — SzController trait
- cookie
- Cookie 模块 — 对齐 PHP
think\Cookie - debug_
page - Whoops-style HTML 调试页面 — 对齐 PHP
whoops异常展示 - env
- Env 模块 — 对齐 PHP
think\facade\Env - error
- 错误体系 — BaseException + 错误码映射
- error_
handler - 错误处理 — 404/500 标准化 JSON 响应
- event
- 事件系统(对齐 PHP
think\Event) - gateway
- Gateway 模块 — GatewayWorker Gateway API 抽象(对齐 PHP
GatewayWorker\Gateway) - guard
- Guard 守卫模块 — 鉴权决策(借鉴 NestJS Guard + Spring Security)
- h2
- HTTP/2 + TLS 支持 — 基于
tokio-rustls+rustls-pki-typesPEM 解析 - health
- 健康检查端点 —
/health - hooks
- 钩子系统接入 — 16 事件 HookDispatcher
- i18n
- i18n 国际化模块 — 对齐 PHP
think\facade\Lang - json
- JSON 模块 — serde_json + simd-json 安全封装
- log
- 日志系统 — 对齐 PHP
think-logger - macros
- 宏模块 —
compact!/#[controller]/#[model]重导出 - Mail 模块 — 对齐 PHP
think\facade\Mail - migration_
history - 迁移历史表(Migration History Table)
- model
- 模型模块 — BaseModel trait + Append 字段系统
- multi_
app - 多应用调度器模块 — MultiAppDispatcher
- multi_
tenant - 多租户支持 — 在 Model 层自动注入 tenant_id 过滤
- notify
- Notify 模块 — 通知抽象层(对齐 PHP
think\facade\Notify) - oauth
- OAuth2 模块 — 对齐 Laravel Socialite
- openapi
- OpenAPI 文档 — 对齐 Swagger / OpenAPI 3.0.3
- pay
- Pay 模块 — 支付聚合抽象层(对齐 PHP
yansongda/pay) - qr_code
- 二维码生成模块 — 对齐 PHP
endroid/qr-code - relation
- 关联关系模块 — HasMany/BelongsTo/HasOne/BelongsToMany/Morph
- request
- 请求模块 — postData/getData/file/upload
- response
- 响应模块 — renderJson/renderSuccess/renderError + ApiResponse
- router
- 路由模块 — 路由构建(基于 axum::Router)
- routing
- 三层路由机制 — 属性宏 / 配置式 / 约定式
- runtime
- SZ-Rust Runtime — Swoole/Worker 适配主入口
- schema_
cache - Schema 缓存模块 — 数据表字段元数据缓存(对齐 PHP
think\db\Fetch::getFields) - seed
- 数据填充(Seed)— 对齐 PHP
think\db\Seed - server
- HTTP 服务器模块 — axum::serve 启动器
- session
- Session 模块 — 对齐 PHP
think\facade\Session - static_
files - 静态文件服务 —
tower-http::services::ServeDir封装 + 自定义文件处理器 - upload
- 文件上传模块 — 对齐 PHP
think\File+think\file\UploadedFile - validate
- 验证器模块 — 对齐 PHP
think\Validate - view
- 视图渲染器 — 对齐 PHP
think\View - websocket_
route - WebSocket 原生路由 — 基于 axum WebSocketUpgrade
- Wechat 模块 — 微信 SDK 抽象层(对齐 PHP
EasyWeChat)
Macros§
- query
- 编译时 SQL 校验 + 可选真实 DB 验证宏 — 复用自
sz-orm-macros - sql_
string - 编译时 SQL 校验宏 — 复用自
sz-orm-macros
Enums§
- SqlStatement
Type - SQL statement type detected by the parser
- SqlValidation
Error - SQL validation errors
Functions§
- detect_
statement_ type - Detect the type of SQL statement
- validate
- Entry-level validation that runs all checks
- validate_
column_ name - Validate column name is a valid SQL identifier
- validate_
delete - Validate a SQL DELETE statement
- validate_
insert - Validate a SQL INSERT statement
- validate_
parameter_ count - Validate parameter count in prepared statements
- validate_
select - Validate a SQL SELECT statement
- validate_
sql - Validate any SQL statement by detecting its type and applying appropriate rules
- validate_
sql_ runtime - 运行时 SQL 校验便捷函数
- validate_
table_ name - Validate table name is a valid SQL identifier
- validate_
update - Validate a SQL UPDATE statement
Type Aliases§
- Validation
Result - Result type for SQL validation