Home >PHP Framework >ThinkPHP >Let's talk about how the TP5.0.x command executes filter!

Let's talk about how the TP5.0.x command executes filter!

藏色散人
藏色散人forward
2022-01-27 17:16:092659browse

The following thinkphp framework tutorial column will introduce to you how to execute filter with Thinkphp5.0.x command. I hope it will be helpful to friends in need!

Thinkphp5.0.x command execution

also uses <span style="color:#c7254e;">call_user_func()</span> for command execution, in the Request class Execute in the function filterValue [Recommended: thinkphp video tutorial]

First search for which functions call filterValue:

In the Request class FilterValue() is called in the cookie() and input() functions

Search for the cookie function call, but no result was found; Search for the input call:

Follow up from the run function:

Step1

In$request = is_null($request) ? Request::instance() : $request;

will execute the constructor of request, and at this time, file_get_contents('php: //input') obtains the content of POST and assigns it to the $request->input variable

##Step2

$dispatch = self::routeCheck($request, $config);

In routeCheck, you will enter the check function of the Route class:

The check function calls $request->method():

Incoming The default value of the parameter is false, and it will be executed in elseif to obtain var_method => _method. The obtained variables will be overwritten below. At this time, if __construct is passed in, $_POST will obtain the data submitted by post, which can be used in the construct function Traverse the POST array to overwrite the members in the request class

The following utilization process requires : Debug mode is on

Param():

will be called in run()

Follow up the param function:

/**

* Get the parameters of the current request

* @access public

* @param string|array $name variable name

* @param mixed $default Default value

* @param string|array $filter filter method

* @return mixed

*/

First enter the if condition and follow up the method method

method() incoming parameter is true:

Execute the following statement: Get the original request type $_SERVER['REQUEST_METHOD'], the return value is POST

Return to param, $ method=POST

Therefore, the POST part in the switch will be executed and the post function will be entered:

post function:

/ **

* Set and obtain POST parameters

* @access public

* @param string $name Variable name

* @param mixed $default Default value

* @param string|array $filter filter method

* @return mixed

*/

Pass in the parameters:

, then copy it to $content, and then $_POST and whether it is in json format are judged. If json is passed in, json_decode is required. Otherwise, the value of $_POST is used directly.

Enter the input method: the incoming parameters are POST The obtained

Name is false, input returns data, and post() directly returns the

param() function Medium: $vars = $this->post(false);

Enter getFilter:

getFilter in$filter = $filter ?: $this-> filter;Get the filter variable value of the $request class (previously covered by construct traversal), and give it as the return value to the input function

Continue executionarray_walk_recursive($data, [$this , 'filterValue'], $filter);

array_walk_recursive() The function applies a user-defined function to each element in the array. In the function, the key name and key value of the array are parameters

is equivalent to $filters=systemtaken from $ Each variable in data is passed in as $value. When ccc=ipconfig is obtained, systemAs the first parameter of call_user_func, ipconfig as the second one, Caused command execution.

Results of the:

The above is the detailed content of Let's talk about how the TP5.0.x command executes filter!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete