diff --git a/library/think/App.php b/library/think/App.php index 3d94c8bf..9f1aaeb0 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -254,9 +254,9 @@ class App $class = $param->getClass(); if ($class) { $className = $class->getName(); - if (isset($vars[$name]) && $vars[$name] instanceof $className) { - $args[] = $vars[$name]; - unset($vars[$name]); + $bind = Request::instance()->$name; + if ($bind instanceof $className) { + $args[] = $bind; } else { $args[] = method_exists($className, 'instance') ? $className::instance() : new $className(); } diff --git a/library/think/Request.php b/library/think/Request.php index a73b4fa5..fb39356f 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -117,6 +117,8 @@ class Request protected static $hook = []; // 绑定的属性 protected $bind = []; + // php://input + protected $input; /** * 架构函数 @@ -133,6 +135,8 @@ class Request if (is_null($this->filter)) { $this->filter = Config::get('default_filter'); } + // 保存 php://input + $this->input = file_get_contents('php://input'); } public function __call($method, $args) @@ -698,7 +702,7 @@ class Request public function put($name = '', $default = null, $filter = null) { if (is_null($this->put)) { - $content = file_get_contents('php://input'); + $content = $this->input; if (strpos($content, '":')) { $this->put = json_decode($content, true); } else { @@ -1416,11 +1420,21 @@ class Request public function getContent() { if (is_null($this->content)) { - $this->content = file_get_contents('php://input'); + $this->content = $this->input; } return $this->content; } + /** + * 获取当前请求的php://input + * @access public + * @return string + */ + public function getInput() + { + return $this->input; + } + /** * 生成请求令牌 * @access public @@ -1464,4 +1478,9 @@ class Request { return isset($this->bind[$name]) ? $this->bind[$name] : null; } + + public function __isset($name) + { + return isset($this->bind[$name]); + } }