mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
改进Response类
This commit is contained in:
@@ -19,6 +19,7 @@ class Json extends Response
|
||||
protected $options = [
|
||||
'json_encode_param' => JSON_UNESCAPED_UNICODE,
|
||||
];
|
||||
|
||||
protected $contentType = 'application/json';
|
||||
/**
|
||||
* 处理数据
|
||||
|
||||
@@ -21,6 +21,7 @@ class Jsonp extends Response
|
||||
'default_jsonp_handler' => 'jsonpReturn',
|
||||
'json_encode_param' => JSON_UNESCAPED_UNICODE,
|
||||
];
|
||||
|
||||
protected $contentType = 'application/javascript';
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,12 @@ class Redirect extends Response
|
||||
// URL参数
|
||||
protected $params = [];
|
||||
|
||||
public function __construct($data = '', $code = 302, array $header = [], array $options = [])
|
||||
{
|
||||
parent::__construct($data, $code, $header, $options);
|
||||
$this->cacheControl('no-cache,must-revalidate');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据
|
||||
* @access protected
|
||||
@@ -32,10 +38,7 @@ class Redirect extends Response
|
||||
*/
|
||||
protected function output($data)
|
||||
{
|
||||
$url = preg_match('/^(https?:|\/)/', $data) ? $data : Url::build($data, $this->params);
|
||||
$this->header['Location'] = $url;
|
||||
$this->header['status'] = isset($this->header['status']) ? $this->header['status'] : 302;
|
||||
$this->header['Cache-control'] = 'no-cache,must-revalidate';
|
||||
$this->header['Location'] = $this->getTargetUrl();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,8 +48,7 @@ class Redirect extends Response
|
||||
*/
|
||||
public function getTargetUrl()
|
||||
{
|
||||
$this->getContent();
|
||||
return $this->header['Location'];
|
||||
return preg_match('/^(https?:|\/)/', $this->data) ? $this->data : Url::build($this->data, $this->params);
|
||||
}
|
||||
|
||||
public function params($params = [])
|
||||
|
||||
Reference in New Issue
Block a user