Download the PHP package tuuz/input without Composer
On this page you can find all versions of the php package tuuz/input. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Vendor tuuz
Package input
Short Description ThinkPHP 8 Input parameter validation package providing type-safe Post/Get extractors (Int/Float/Bool/DateTime/Json) and Conventional Commits message analyzer. Compatible with PHP 8.5+.
License MIT
Package input
Short Description ThinkPHP 8 Input parameter validation package providing type-safe Post/Get extractors (Int/Float/Bool/DateTime/Json) and Conventional Commits message analyzer. Compatible with PHP 8.5+.
License MIT
Please rate this library. Is it a good library?
Informations about the package input
tuuz/input
ThinkPHP 8.1+ 参数校验与 JSON 响应一体化组件包。
- Input:类型安全的 HTTP 参数提取器(Post / Get / Combi / Raw),自动触发参数缺失或类型错误的失败响应。
- Ret:统一 JSON 响应类,包含 Success / Fail 及常用 HTTP 状态码快捷方法。
- CommitMessage\Analyzer:基于 Conventional Commits 规范的提交信息解析与描述生成器。
- removeXSS():基于 HTMLPurifier 的 XSS 清洗助手函数(可选依赖)。
要求 PHP 8.5 及以上。
安装
ThinkPHP 8 会通过 extra.think.aliases 自动注册门面别名 Input 与 Ret,无需额外配置即可在全局直接使用。
可选依赖(启用高级 XSS 清洗):
Input:参数提取(Input::)
所有 Post* / Get* 方法签名相同:
$must_have = true:缺失 / 类型不匹配 → 自动Ret::Fail(400, ...)输出 JSON 并 exit
| 方法 | 返回类型 | 说明 |
|---|---|---|
Input::Post($name, $must, $xss) |
string |
POST 字符串 |
Input::PostInt($name, $must) |
int |
POST 整数 |
Input::PostFloat($name, $must) |
float |
POST 浮点数 |
Input::PostBool($name, $must) |
bool |
POST 布尔 |
Input::PostDateTime($name, $must) |
string\|null |
RFC3339 格式时间 |
Input::PostJson($name, $must) |
array |
JSON 字符串 → 数组 |
Input::Get($name, $must, $xss) |
string |
GET 字符串 |
Input::GetInt($name, $must) |
int |
GET 整数 |
Input::GetFloat($name, $must) |
float |
GET 浮点数 |
Input::GetBool($name, $must) |
bool |
GET 布尔 |
Input::GetDateTime($name, $must) |
string\|null |
RFC3339 格式时间 |
Input::GetJson($name, $must) |
array |
JSON 字符串 → 数组 |
Input::Combi($name, $must, $xss) |
string |
POST 优先,其次 GET |
Input::Raw() |
string |
原始 php://input |
Post/Get/Combi 的第三个参数 $xss = true 会对值调用 strip_tags 做基础 XSS 过滤。
示例:
替换默认失败响应类
Input 默认使用包内的 Ret::Fail。若需改用项目自定义响应类:
目标类需具备静态方法 Fail(int $code, mixed $data, string $msg): void。
Ret:JSON 响应(Ret::)
基础
输出格式统一:
HTTP 快捷方法
| 方法 | 默认 code | 默认 echo |
|---|---|---|
Ret::Ok($data, $echo) |
0 | 成功 |
Ret::BadRequest($echo, $data) |
400 | 参数错误 |
Ret::Unauthorized($echo, $data) |
401 | 鉴权失败 |
Ret::Forbidden($echo, $data) |
403 | 权限不足 |
Ret::NotFound($echo, $data) |
404 | 未找到数据 |
Ret::ServerError($echo, $data) |
500 | 数据库错误 |
Ret::Error($code, $echo, $data) |
任意 | 失败 |
内置 code → 默认提示词对照表
| code | 文案 |
|---|---|
| 0 | 成功 |
| -1 | 登录失效请重新登录 |
| 400 | 参数错误 |
| 401 | 鉴权失败 |
| 403 | 权限不足 |
| 404 | 未找到数据 |
| 406 / 407 | 数据不符合期待 |
| 500 | 数据库错误 |
| 其他 | 失败 |
运行时配置
纯构造(不 exit / 不 echo)
removeXSS() 助手函数
- 未安装
ezyang/htmlpurifier时原样返回。 - 非字符串入参原样返回。
- 白名单标签:
div,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]。 - 白名单 CSS 属性:
font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align。 HTML.TargetBlank = true。
CommitMessage\Analyzer:提交信息解析与描述生成
基于 Conventional Commits 规范。
基础 API
| 方法 | 说明 |
|---|---|
$a->isValid() |
是否符合规范 |
$a->getType() |
feat / fix / ... |
$a->getTypeDescription() |
类型英文描述 |
$a->getScope() |
input 或 null |
$a->isBreakingChange() |
是否破坏性变更(header ! 或 footer BREAKING CHANGE) |
$a->getSubject() |
主语 |
$a->getBody() |
正文 |
$a->getFooter() |
页脚 |
$a->getErrors() |
校验错误数组 |
$a->getMessage() |
原始消息 |
$a->toArray() |
数组导出 |
$a->generateDescription() |
生成带 Markdown 格式的人类可读描述 |
$a->getBumpLevel() |
SemVer 升级级别:major / minor / patch,无法判断返回 null |
generateDescription() 示例输出
SemVer 升级级别判定
| 条件 | 级别 |
|---|---|
! 或 footer BREAKING CHANGE |
major |
type === feat |
minor |
type === fix 或 type === perf |
patch |
| 其他类型 | null |
支持的提交类型
| type | description |
|---|---|
| feat | A new feature |
| fix | A bug fix |
| docs | Documentation only changes |
| style | Changes that do not affect the meaning of the code |
| refactor | A code change that neither fixes a bug nor adds a feature |
| perf | A code change that improves performance |
| test | Adding missing tests or correcting existing tests |
| chore | Changes to the build process or auxiliary tools |
| build | Changes that affect the build system or external dependencies |
| ci | Changes to CI configuration files and scripts |
| revert | Reverts a previous commit |
校验规则
- Header 必须满足:
type(scope)!: subject subject长度 ≤ 50,不允许以.结尾- body / footer 每行 ≤ 72 字符
- 错误信息通过
getErrors()返回
命名空间类名对照
| 用途 | 推荐调用方式 | 完全限定名(FQSEN) |
|---|---|---|
| 门面 Input | Input::xxx() |
Tuuz\Input\Facade\Input |
| 门面 Ret | Ret::xxx() |
Tuuz\Input\Facade\Ret |
| 核心 Input | use Tuuz\Input\Input |
Tuuz\Input\Input |
| 核心 Ret | use Tuuz\Input\Ret |
Tuuz\Input\Ret |
| 提交解析器 | use Tuuz\Input\CommitMessage\Analyzer |
Tuuz\Input\CommitMessage\Analyzer |
| XSS 助手 | 全局函数 | removeXSS()(Tuuz\Input\Helper\functions.php) |
License
MIT
All versions of input with dependencies
PHP Build Version
Package Version
The package tuuz/input contains the following files
Loading the files please wait ...