rain_sunshine_cloud / request
There is no license information available for the latest version (v1.0) of this package.
这是一起请求接收参数类
v1.0
2019-04-05 08:14 UTC
This package is auto-updated.
Last update: 2025-04-17 20:19:16 UTC
README
这是一个接收请求参数的封装类
说明
- 支持post get serv(获取$_SERVER) patch delete put 请求
- 支持json格式的payload请求方式 (通过setDataType 设置数据来源)
- 自带类型转换(如 int 会自动帮忙转为 int)
- 支持链式操作,
- 支持验证其他数据源,通过 data($data)
- 支持默认值操作
- 支持闭包验证
- 支持自定义的类验证
- 采用异常抛出的方式,返回错误信息
- 灵活的第三方参数传递
- 支持单例
基本用法
class Test {
public static function int($val,$err_message,$other_params)
{
return 2343;
}
public function float($val,$err_message,$other_params)
{
return 23423;
}
}
try {
$_POST['a'] = 2;
//使用方法1
$request = new Request();
$res = $request->check('a','int','必须是整数1')->post('a');
//使用方法2
$res = Request::instance()->check('a','int','必须是整数2')->post(['a','b','c' => '1']);
//使用方法3
$res = Request::instance()->check('a','int','必须是整数2')->check('c','float','必须大于4',['min' => 4])->post(['a','b','c' => '4']);
//使用方法4
$res = Request::instance()->check('a',['test','int'],'必须是整数2')->check('c','float','必须大于4',['min' => 4])->post(['a','b','c' => '4']);
//使用方法5
$res = Request::instance()->check('a',[new Test(),'int'],'必须是整数2')->check('c','float','必须大于4',['min' => 4])->post(['a','b','c' => '4']);
var_dump($res);
} catch (RequestException $e) {
echo $e->getMessage();
}