|
|
|
@ -35,7 +35,7 @@ class Response extends \yii\base\Response
|
|
|
|
|
* @event ResponseEvent an event that is triggered right after [[prepare()]] is called in [[send()]]. |
|
|
|
|
* You may respond to this event to filter the response content before it is sent to the client. |
|
|
|
|
*/ |
|
|
|
|
const EVENT_PREPARE = 'prepare'; |
|
|
|
|
const EVENT_AFTER_PREPARE = 'afterPrepare'; |
|
|
|
|
|
|
|
|
|
const FORMAT_RAW = 'raw'; |
|
|
|
|
const FORMAT_HTML = 'html'; |
|
|
|
@ -218,6 +218,11 @@ class Response extends \yii\base\Response
|
|
|
|
|
*/ |
|
|
|
|
public function setStatusCode($value, $text = null) |
|
|
|
|
{ |
|
|
|
|
if ($value === null) { |
|
|
|
|
$this->_statusCode = null; |
|
|
|
|
$this->statusText = null; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
$this->_statusCode = (int)$value; |
|
|
|
|
if ($this->getIsInvalid()) { |
|
|
|
|
throw new InvalidParamException("The HTTP status code is invalid: $value"); |
|
|
|
@ -249,7 +254,7 @@ class Response extends \yii\base\Response
|
|
|
|
|
{ |
|
|
|
|
$this->trigger(self::EVENT_BEFORE_SEND, new ResponseEvent($this)); |
|
|
|
|
$this->prepare(); |
|
|
|
|
$this->trigger(self::EVENT_PREPARE, new ResponseEvent($this)); |
|
|
|
|
$this->trigger(self::EVENT_AFTER_PREPARE, new ResponseEvent($this)); |
|
|
|
|
$this->sendHeaders(); |
|
|
|
|
$this->sendContent(); |
|
|
|
|
$this->trigger(self::EVENT_AFTER_SEND, new ResponseEvent($this)); |
|
|
|
@ -319,14 +324,8 @@ class Response extends \yii\base\Response
|
|
|
|
|
*/ |
|
|
|
|
protected function sendContent() |
|
|
|
|
{ |
|
|
|
|
if (is_array($this->content)) { |
|
|
|
|
echo 'array()'; |
|
|
|
|
} elseif (is_object($this->content)) { |
|
|
|
|
echo method_exists($this->content, '__toString') ? (string)$this->content : get_class($this->content); |
|
|
|
|
} else { |
|
|
|
|
echo $this->content; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sends a file to the browser. |
|
|
|
@ -721,12 +720,10 @@ class Response extends \yii\base\Response
|
|
|
|
|
} |
|
|
|
|
if ($formatter instanceof ResponseFormatter) { |
|
|
|
|
$formatter->format($this); |
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
|
throw new InvalidConfigException("The '{$this->format}' response formatter is invalid. It must implement the ResponseFormatter interface."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
switch ($this->format) { |
|
|
|
|
case self::FORMAT_HTML: |
|
|
|
|
$this->getHeaders()->setDefault('Content-Type', 'text/html; charset=' . $this->charset); |
|
|
|
@ -755,4 +752,11 @@ class Response extends \yii\base\Response
|
|
|
|
|
throw new InvalidConfigException("Unsupported response format: {$this->format}"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (is_array($this->content)) { |
|
|
|
|
$this->content = 'array()'; |
|
|
|
|
} elseif (is_object($this->content)) { |
|
|
|
|
$this->content = method_exists($this->content, '__toString') ? (string)$this->content : get_class($this->content); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|