public function set($id, $params, $method_info)
{
Verify::isTrue(is_array($params) || is_string($params), "{$this->class_name}::{$this->method_name} invalid @return");
if (is_string($params)) {
$to = $params;
$from = array();
} else {
$to = $params[0];
$from = array_slice($params, 1);
}
$to_func =& $this->params[$to][$id];
if ($this->auto_bind_return && ($to == 'body' || $to == 'res') && isset($this->params['body'][-1])) {
unset($this->params['body'][-1]);
// 指定了body输出, 去掉默认的body输出
}
if (0 === count($from)) {
$to_func[0] = array(false, null, -1, null);
}
foreach ($from as $index => $name) {
// 输入方法 $index变量序号 $name变量名
$is_const = substr($name, 0, 1) != '$';
if ($is_const) {
// 输出常量, 不需要绑定变量
$to_func[$index] = array(true, $name, 0, null);
//[是否常量, 值 , 参数来源位置, 参数信息]
continue;
}
$name = substr($name, 1);
//变量输出, 需要绑定
$pos = -1;
$step = 0;
//是(输出)方法的第几个参数
foreach ($method_info as $item) {
list($param_name, ) = $item;
if ($name === $param_name) {
$pos = $step;
break;
}
$step++;
}
Verify::isTrue($pos !== -1, "{$this->class_name}::{$this->method_name} param: {$name} not found");
//只能是引用
list(, $is_ref, ) = $item;
Verify::isTrue($is_ref, "{$this->class_name}::{$this->method_name} param: {$name} @return must be a reference");
$to_func[$index] = array(false, $name, $pos, $item);
//[是否常量, 值 , 参数位置, 参数信息]
}
}