首页›输入处理›Input 类总览
Input 类总览
Kuoqi\Core\Input(276 行)是输入处理核心:来源判定 + 深层取值 + 过滤
本页内容
- 属性
- 静态读写接口
属性
| 属性 | 说明 |
|---|---|
$__name | 多级 key 数组(explode(".") 拆分) |
$__method | 来源:get/post/json/server/request |
$__default_value / $__filter / $__value | 默认值 / 过滤器 / 最终值 |
static $__GETS / $__POSTS / $__JSONS | 全局输入容器(GET 可被路由参数注入) |
static $__REQUEST_BODY | php://input 原始请求体 |
静态初始化
public static function __initialize(){
parent::__initialize();
\Kuoqi::$IS_WEB && (self::$__REQUEST_BODY = file_get_contents("PHP://input"));
self::$__POSTS = $_POST;
self::$__JSONS = json_decode(self::$__REQUEST_BODY, true);
if(!is_array(self::$__JSONS)){
self::$__JSONS = array();
}
}核心流程
public function getValue(){
switch($this->__method){
case "get": $this->getValueWithGet(); break;
case "post": $this->getValueWithPost(); break;
case "json": $this->getValueWithJson(); break;
case "server": $this->getValueWithServer(); break;
default: $this->getValueWithRequest(); break;
}
// 过滤器返回 null 时使用默认值
$data = FilterInputModel::filter($this->__filter, $this->__value);
$this->__value = ($data === null) ? $this->__default_value : $data;
return $this->__value;
}静态读写接口
| 方法 | 签名 | 说明 |
|---|---|---|
setInputget(s) | setInputget($name,$value=null) / setInputgets($range) | 写入 GET(路由额外参数经此注入) |
setInputpost | setInputpost($m,$v=null) | 写入 POST(数组/单值) |
setInputjson(s) | setInputjson($m,$v=null) | 写入 JSON |
getInputgets/posts/jsons | getInputxxx() | 读取各来源数组 |
getInputrequest | getInputrequest() | GET+POST+JSON 合并 |
getRequestBody | getRequestBody() | 原始请求体 |
waitInput | waitInput() | 等待 stdin 输入一行(CLI 交互) |
KuoqiPHP v1.05 · 离线静态文档 · 界面基于 KuoqiUI ·
返回首页