mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进操作方法的对象自动注入 Requesst类增加getInput方法 用于获取 php://input值
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user