一、属性
1. $_cookies CookieCollection实例
//CookieCollection实例
private $_cookies;
二、方法
1. getCookies方法,返回CookieCollection实例
// 返回CookieCollection实例
public function getCookies()
{
if ($this->_cookies === null) {
$this->_cookies = new CookieCollection();
}
return $this->_cookies;
}
2. defaultFormatters方法,默认支持的响应内容格式
// 默认支持的响应内容格式
protected function defaultFormatters()
{
return [
self::FORMAT_HTML => [
'class' => 'yii\web\HtmlResponseFormatter',
],
self::FORMAT_XML => [
'class' => 'yii\web\XmlResponseFormatter',
],
self::FORMAT_JSON => [
'class' => 'yii\web\JsonResponseFormatter',
],
self::FORMAT_JSONP => [
'class' => 'yii\web\JsonResponseFormatter',
'useJsonp' => true,
],
];
}
3. prepare方法,准备发送响应
//准备发送响应
protected function prepare()
{
if (in_array($this->getStatusCode(), [204, 304])) {
// A 204/304 response cannot contain a message body according to rfc7231/rfc7232
$this->content = '';
$this->stream = null;
return;
}
if ($this->stream !== null) {
return;
}
if (isset($this->formatters[$this->format])) {
$formatter = $this->formatters[$this->format];
if (!is_object($formatter)) {
$this->formatters[$this->format] = $formatter = Yii::createObject($formatter);
}
if ($formatter instanceof ResponseFormatterInterface) {
$formatter->format($this);
} else {
throw new InvalidConfigException("The '{$this->format}' response formatter is invalid. It must implement the ResponseFormatterInterface.");
}
} elseif ($this->format === self::FORMAT_RAW) {
if ($this->data !== null) {
$this->content = $this->data;
}
} else {
throw new InvalidConfigException("Unsupported response format: {$this->format}");
}
if (is_array($this->content)) {
throw new InvalidArgumentException('Response content must not be an array.');
} elseif (is_object($this->content)) {
if (method_exists($this->content, '__toString')) {
$this->content = $this->content->__toString();
} else {
throw new InvalidArgumentException('Response content must be a string or an object implementing __toString().');
}
}
}
4. isSeekable方法,检查流是否可查找
//检查流是否可查找
private function isSeekable($handle)
{
if (!is_resource($handle)) {
return true;
}
$metaData = stream_get_meta_data($handle);
return isset($metaData['seekable']) &&
$metaData['seekable'] === true;
}
总结:
阅读了1个属性和4个方法:
- $_cookies CookieCollection实例
- getCookies方法,返回CookieCollection实例
- defaultFormatters方法,默认支持的响应内容格式
- prepare方法,准备发送响应
- isSeekable方法,检查流是否可查找