Browse Source

Fix #18394: Add support for setting `yii\web\Response::$stream` to a callable

tags/2.0.40
Brandon Kelly 4 years ago committed by GitHub
parent
commit
279f59a3d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      framework/CHANGELOG.md
  2. 18
      framework/web/Response.php

2
framework/CHANGELOG.md

@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.40 under development
------------------------
- no changes in this release.
- Enh #18394: Add support for setting `yii\web\Response::$stream` to a callable (brandonkelly)
2.0.39.3 November 23, 2020

18
framework/web/Response.php

@ -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)) {

Loading…
Cancel
Save