改进Response类

This commit is contained in:
yunwuxin
2016-06-21 12:09:39 +08:00
parent 2281f1edb4
commit 91ab9dfde0
8 changed files with 109 additions and 143 deletions

View File

@@ -19,6 +19,7 @@ class Json extends Response
protected $options = [
'json_encode_param' => JSON_UNESCAPED_UNICODE,
];
protected $contentType = 'application/json';
/**
* 处理数据

View File

@@ -21,6 +21,7 @@ class Jsonp extends Response
'default_jsonp_handler' => 'jsonpReturn',
'json_encode_param' => JSON_UNESCAPED_UNICODE,
];
protected $contentType = 'application/javascript';
/**

View File

@@ -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 = [])