Request类增加bind方法用于动态绑定属性 Route类的模型绑定直接绑定到Request实例对象的属性 便于获取

This commit is contained in:
thinkphp
2016-09-12 15:47:52 +08:00
parent fc0a761165
commit 3a983aa3e1
2 changed files with 29 additions and 1 deletions

View File

@@ -115,6 +115,8 @@ class Request
protected $filter;
// Hook扩展方法
protected static $hook = [];
// 绑定的属性
protected $bind = [];
/**
* 架构函数
@@ -1436,4 +1438,30 @@ class Request
Session::set($name, $token);
return $token;
}
/**
* 设置当前请求绑定的对象实例
* @access public
* @param string $name 绑定的对象标识
* @param mixed $obj 绑定的对象实例
* @return mixed
*/
public function bind($name, $obj = null)
{
if (is_array($name)) {
$this->bind = array_merge($this->bind, $name);
} else {
$this->bind[$name] = $obj;
}
}
public function __set($name, $value)
{
$this->bind[$name] = $value;
}
public function __get($name)
{
return isset($this->bind[$name]) ? $this->bind[$name] : null;
}
}

View File

@@ -1367,7 +1367,7 @@ class Route
$bind[$key] = $result;
}
}
$matches = array_merge($matches, $bind);
Request::instance()->bind($bind);
}
// 解析额外参数