From 3a983aa3e1dcc079e85d94787b81064ba50950fc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 12 Sep 2016 15:47:52 +0800 Subject: [PATCH] =?UTF-8?q?Request=E7=B1=BB=E5=A2=9E=E5=8A=A0bind=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=94=A8=E4=BA=8E=E5=8A=A8=E6=80=81=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=20Route=E7=B1=BB=E7=9A=84=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E7=9B=B4=E6=8E=A5=E7=BB=91=E5=AE=9A=E5=88=B0?= =?UTF-8?q?Request=E5=AE=9E=E4=BE=8B=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=20=E4=BE=BF=E4=BA=8E=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 28 ++++++++++++++++++++++++++++ library/think/Route.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/library/think/Request.php b/library/think/Request.php index c34a4b14..a73b4fa5 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -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; + } } diff --git a/library/think/Route.php b/library/think/Route.php index dfbb5b81..50563671 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1367,7 +1367,7 @@ class Route $bind[$key] = $result; } } - $matches = array_merge($matches, $bind); + Request::instance()->bind($bind); } // 解析额外参数