mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进操作方法的对象自动注入 Requesst类增加getInput方法 用于获取 php://input值
This commit is contained in:
@@ -254,9 +254,9 @@ class App
|
|||||||
$class = $param->getClass();
|
$class = $param->getClass();
|
||||||
if ($class) {
|
if ($class) {
|
||||||
$className = $class->getName();
|
$className = $class->getName();
|
||||||
if (isset($vars[$name]) && $vars[$name] instanceof $className) {
|
$bind = Request::instance()->$name;
|
||||||
$args[] = $vars[$name];
|
if ($bind instanceof $className) {
|
||||||
unset($vars[$name]);
|
$args[] = $bind;
|
||||||
} else {
|
} else {
|
||||||
$args[] = method_exists($className, 'instance') ? $className::instance() : new $className();
|
$args[] = method_exists($className, 'instance') ? $className::instance() : new $className();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,8 @@ class Request
|
|||||||
protected static $hook = [];
|
protected static $hook = [];
|
||||||
// 绑定的属性
|
// 绑定的属性
|
||||||
protected $bind = [];
|
protected $bind = [];
|
||||||
|
// php://input
|
||||||
|
protected $input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 架构函数
|
* 架构函数
|
||||||
@@ -133,6 +135,8 @@ class Request
|
|||||||
if (is_null($this->filter)) {
|
if (is_null($this->filter)) {
|
||||||
$this->filter = Config::get('default_filter');
|
$this->filter = Config::get('default_filter');
|
||||||
}
|
}
|
||||||
|
// 保存 php://input
|
||||||
|
$this->input = file_get_contents('php://input');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __call($method, $args)
|
public function __call($method, $args)
|
||||||
@@ -698,7 +702,7 @@ class Request
|
|||||||
public function put($name = '', $default = null, $filter = null)
|
public function put($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
if (is_null($this->put)) {
|
if (is_null($this->put)) {
|
||||||
$content = file_get_contents('php://input');
|
$content = $this->input;
|
||||||
if (strpos($content, '":')) {
|
if (strpos($content, '":')) {
|
||||||
$this->put = json_decode($content, true);
|
$this->put = json_decode($content, true);
|
||||||
} else {
|
} else {
|
||||||
@@ -1416,11 +1420,21 @@ class Request
|
|||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
if (is_null($this->content)) {
|
if (is_null($this->content)) {
|
||||||
$this->content = file_get_contents('php://input');
|
$this->content = $this->input;
|
||||||
}
|
}
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前请求的php://input
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getInput()
|
||||||
|
{
|
||||||
|
return $this->input;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成请求令牌
|
* 生成请求令牌
|
||||||
* @access public
|
* @access public
|
||||||
@@ -1464,4 +1478,9 @@ class Request
|
|||||||
{
|
{
|
||||||
return isset($this->bind[$name]) ? $this->bind[$name] : null;
|
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