mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 22:32:40 +08:00
Fix #18394: Add support for setting yii\web\Response::$stream to a callable
This commit is contained in:
@ -138,9 +138,12 @@ class Response extends \yii\base\Response
|
||||
*/
|
||||
public $content;
|
||||
/**
|
||||
* @var resource|array the stream to be sent. This can be a stream handle or an array of stream handle,
|
||||
* the begin position and the end position. Note that when this property is set, the [[data]] and [[content]]
|
||||
* properties will be ignored by [[send()]].
|
||||
* @var resource|array|callable the stream to be sent. This can be a stream handle or an array of stream handle,
|
||||
* the begin position and the end position. Alternatively it can be set to a callable, which returns
|
||||
* (or [yields](https://www.php.net/manual/en/language.generators.syntax.php)) an array of strings that should
|
||||
* be echoed and flushed out one by one.
|
||||
*
|
||||
* Note that when this property is set, the [[data]] and [[content]] properties will be ignored by [[send()]].
|
||||
*/
|
||||
public $stream;
|
||||
/**
|
||||
@ -441,6 +444,15 @@ class Response extends \yii\base\Response
|
||||
Yii::warning('set_time_limit() is not available', __METHOD__);
|
||||
}
|
||||
|
||||
if (is_callable($this->stream)) {
|
||||
$data = call_user_func($this->stream);
|
||||
foreach ($data as $datum) {
|
||||
echo $datum;
|
||||
flush();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$chunkSize = 8 * 1024 * 1024; // 8MB per chunk
|
||||
|
||||
if (is_array($this->stream)) {
|
||||
|
||||
Reference in New Issue
Block a user