|
|
@ -13,23 +13,29 @@ namespace yii\base; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class Response extends Component |
|
|
|
class Response extends Component |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @event Event an event raised when the application begins to generate the response. |
|
|
|
|
|
|
|
*/ |
|
|
|
const EVENT_BEGIN_RESPONSE = 'beginResponse'; |
|
|
|
const EVENT_BEGIN_RESPONSE = 'beginResponse'; |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @event Event an event raised when the generation of the response finishes. |
|
|
|
|
|
|
|
*/ |
|
|
|
const EVENT_END_RESPONSE = 'endResponse'; |
|
|
|
const EVENT_END_RESPONSE = 'endResponse'; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Starts output buffering |
|
|
|
* Starts output buffering |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function beginOutput() |
|
|
|
public function beginBuffer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
ob_start(); |
|
|
|
ob_start(); |
|
|
|
ob_implicit_flush(false); |
|
|
|
ob_implicit_flush(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns contents of the output buffer and discards it |
|
|
|
* Returns contents of the output buffer and stops the buffer. |
|
|
|
* @return string output buffer contents |
|
|
|
* @return string output buffer contents |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function endOutput() |
|
|
|
public function endBuffer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return ob_get_clean(); |
|
|
|
return ob_get_clean(); |
|
|
|
} |
|
|
|
} |
|
|
@ -38,16 +44,16 @@ class Response extends Component |
|
|
|
* Returns contents of the output buffer |
|
|
|
* Returns contents of the output buffer |
|
|
|
* @return string output buffer contents |
|
|
|
* @return string output buffer contents |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function getOutput() |
|
|
|
public function getBuffer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return ob_get_contents(); |
|
|
|
return ob_get_contents(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Discards the output buffer |
|
|
|
* Discards the output buffer |
|
|
|
* @param boolean $all if true recursively discards all output buffers used |
|
|
|
* @param boolean $all if true, it will discards all output buffers. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function cleanOutput($all = true) |
|
|
|
public function cleanBuffer($all = true) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($all) { |
|
|
|
if ($all) { |
|
|
|
for ($level = ob_get_level(); $level > 0; --$level) { |
|
|
|
for ($level = ob_get_level(); $level > 0; --$level) { |
|
|
@ -60,11 +66,25 @@ class Response extends Component |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Begins generating the response. |
|
|
|
|
|
|
|
* This method is called at the beginning of [[Application::run()]]. |
|
|
|
|
|
|
|
* The default implementation will trigger the [[EVENT_BEGIN_RESPONSE]] event. |
|
|
|
|
|
|
|
* If you overwrite this method, make sure you call the parent implementation so that |
|
|
|
|
|
|
|
* the event can be triggered. |
|
|
|
|
|
|
|
*/ |
|
|
|
public function begin() |
|
|
|
public function begin() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->trigger(self::EVENT_BEGIN_RESPONSE); |
|
|
|
$this->trigger(self::EVENT_BEGIN_RESPONSE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Ends generating the response. |
|
|
|
|
|
|
|
* This method is called at the end of [[Application::run()]]. |
|
|
|
|
|
|
|
* The default implementation will trigger the [[EVENT_END_RESPONSE]] event. |
|
|
|
|
|
|
|
* If you overwrite this method, make sure you call the parent implementation so that |
|
|
|
|
|
|
|
* the event can be triggered. |
|
|
|
|
|
|
|
*/ |
|
|
|
public function end() |
|
|
|
public function end() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->trigger(self::EVENT_END_RESPONSE); |
|
|
|
$this->trigger(self::EVENT_END_RESPONSE); |
|
|
|