PHP code example of tuuz / input
1. Go to this page and download the library: Download tuuz/input library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tuuz / input example snippets
$id = Input::PostInt('id'); // 0 也合法(严格判空)
$name = Input::Post('name', true, true); // 必须且 XSS 过滤
$page = Input::GetInt('page', false) ?: 1; // 非必须,默认 1
$enabled = Input::PostBool('enabled'); // true / false 皆合法
$tags = Input::PostJson('tags'); // 解析为数组
Input::setRetClass(\app\common\MyRet::class);
Ret::Success(0, ['id' => 1, 'name' => 'x'], '操作成功');
Ret::Ok(['list' => [...]]); // code=0 简写
Ret::Fail(400, [], '参数错误');
Ret::Error(400, '缺少字段 id');
// 覆盖或追加状态码文案(i18n / 项目自定义)
Ret::setMessage(1001, '库存不足');
Ret::setMessages([-2 => '签名过期', 1002 => '频率超限']);
Ret::getMessages();
// 单元测试 / SSE 等特殊场景:只输出不 exit
Ret::setExitAfterSend(false);
Ret::setExitAfterSend(true, 0); // 第二个参数是 exit code
// 自定义 Content-Type(传 null 则不发送任何头)
Ret::setContentType('application/json; charset=utf-8');
Ret::setContentType(null);
$array = Ret::build(0, ['a' => 1]);
// ['code'=>0, 'data'=>['a'=>1], 'echo'=>'成功']
$json = Ret::toJson(400, [], '缺少参数 id');
// 直接返回 JSON 字符串,供队列/日志/测试使用
$cleanHtml = removeXSS($userInput);
use Tuuz\Input\CommitMessage\Analyzer;
$msg = "feat(input)!: add GetInt method
Adds a typed getter for query-string integers
BREAKING CHANGE: minimum PHP version bumped to 8.5
Refs: #123";
$a = Analyzer::from($msg);
Analyzer::getTypeDescriptions();
json
{"code":0,"data":[],"echo":"成功"}