您好,欢迎访问一九零五行业门户网

说说TP5.0.x命令是如何执行filter的!

下面thinkphp框架教程栏目将给大家介绍thinkphp5.0.x命令怎么执行filter,希望对需要的朋友有所帮助!
thinkphp5.0.x命令执行
同样是利用call_user_func()进行命令执行,在request类的函数filtervalue中执行【推荐:thinkphp视频教程】
首先搜索哪些函数调用了filtervalue:
在request类中的cookie()和input()函数中调用了filtervalue()
搜索cookie函数调用情况,未发现结果;搜索input调用情况:
从run函数跟进:
step1
在$request = is_null($request) ? request::instance() : $request;
会执行request的构造函数,此时已经通过构造函数中file_get_contents(‘php://input’)获取到了post的内容并赋值给$request->input变量
step2
$dispatch = self::routecheck($request, $config);
在routecheck中会进入route类的check函数:
check函数调用了$request->method():
传入参数默认值为false,会执行到elseif中获取var_method => _method,下面会对获取到的变量进行覆盖,此时如果传入__construct,$_post获取到post提交的数据,即可在construct函数中遍历post的数组对request类中的成员进行覆盖
以下利用过程需要:debug模式开启在run()中会调用param():
跟进param函数:
    /**
     * 获取当前请求的参数
     * @access public
     * @param string|array  $name 变量名
     * @param mixed         $default 默认值
     * @param string|array  $filter 过滤方法
     * @return mixed
     */
首先进入if条件,跟进method方法
method()传入参数为true:
执行下面语句:获取原始请求类型$_server['request_method'],返回值为post
返回到param中,$method=post
因此会执行switch中的post部分,进入post函数:
post函数:
    /**
     * 设置获取post参数
     * @access public
     * @param string        $name 变量名
     * @param mixed         $default 默认值
     * @param string|array  $filter 过滤方法
     * @return mixed
     */
传入参数:
,然后复制给$content,然后对$_post和是否json格式判断,如果是json传入还需要进行json_decode,否则直接使用$_post的值
进入input方法:传入参数为post所获取到的
name为false,input返回data,post()直接返回
param()函数中:$vars = $this->post(false);
进入getfilter:
getfilter中$filter = $filter ?: $this->filter;获取到$request类的filter变量值(之前在construct遍历覆盖的),并作为返回值给input函数
继续执行array_walk_recursive($data, [$this, 'filtervalue'], $filter);
array_walk_recursive() 函数对数组中的每个元素应用用户自定义函数。在函数中,数组的键名和键值是参数
相当于$filters=system取$data中的每一个变量作为$value传入,当取到ccc=ipconfig时,system作为call_user_func第一个参数,ipconfig作为第二个,造成了命令执行。
执行结果:
以上就是说说tp5.0.x命令是如何执行filter的!的详细内容。
其它类似信息

推荐信息