内核更新
This commit is contained in:
@@ -117,6 +117,10 @@ class Request
|
||||
protected static $hook = [];
|
||||
// 绑定的属性
|
||||
protected $bind = [];
|
||||
// php://input
|
||||
protected $input;
|
||||
// 请求缓存
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* 架构函数
|
||||
@@ -133,6 +137,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 +704,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 {
|
||||
@@ -1180,22 +1186,34 @@ class Request
|
||||
/**
|
||||
* 当前是否Ajax请求
|
||||
* @access public
|
||||
* @param bool $ajax true 获取原始ajax请求
|
||||
* @return bool
|
||||
*/
|
||||
public function isAjax()
|
||||
public function isAjax($ajax = false)
|
||||
{
|
||||
$value = $this->server('HTTP_X_REQUESTED_WITH');
|
||||
return (!is_null($value) && strtolower($value) == 'xmlhttprequest') ? true : false;
|
||||
$value = $this->server('HTTP_X_REQUESTED_WITH', '', 'strtolower');
|
||||
$result = ('xmlhttprequest' == $value) ? true : false;
|
||||
if (true === $ajax) {
|
||||
return $result;
|
||||
} else {
|
||||
return $this->param(Config::get('var_ajax')) ? true : $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前是否Pjax请求
|
||||
* @access public
|
||||
* @param bool $pjax true 获取原始pjax请求
|
||||
* @return bool
|
||||
*/
|
||||
public function isPjax()
|
||||
public function isPjax($pjax = false)
|
||||
{
|
||||
return !is_null($this->server('HTTP_X_PJAX')) ? true : false;
|
||||
$result = !is_null($this->server('HTTP_X_PJAX')) ? true : false;
|
||||
if (true === $pjax) {
|
||||
return $result;
|
||||
} else {
|
||||
return $this->param(Config::get('var_pjax')) ? true : $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1416,11 +1434,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
|
||||
@@ -1439,6 +1467,45 @@ class Request
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取或者设置缓存
|
||||
* @access public
|
||||
* @param string $key 缓存标识,支持变量规则 ,例如 item/:name/:id
|
||||
* @param mixed $expire 缓存有效期
|
||||
* @return mixed
|
||||
*/
|
||||
public function cache($key, $expire = null)
|
||||
{
|
||||
if (false !== strpos($key, ':')) {
|
||||
$param = $this->param();
|
||||
foreach ($param as $item => $val) {
|
||||
if (is_string($val) && false !== strpos($key, ':' . $item)) {
|
||||
$key = str_replace(':' . $item, $val, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Cache::has($key)) {
|
||||
// 读取缓存
|
||||
$content = Cache::get($key);
|
||||
$response = Response::create($content)
|
||||
->code(304)
|
||||
->header('Content-Type', Cache::get($key . '_header'));
|
||||
throw new \think\exception\HttpResponseException($response);
|
||||
} else {
|
||||
$this->cache = [$key, $expire];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取缓存设置
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getCache()
|
||||
{
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前请求绑定的对象实例
|
||||
* @access public
|
||||
@@ -1464,4 +1531,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