@@ -15,15 +15,23 @@ class SapiStreamEmitter implements EmitterInterface
1515{
1616 use SapiEmitterTrait;
1717
18+ /**
19+ * @var int Maximum output buffering size for each iteration.
20+ */
21+ private $ maxBufferLength ;
22+
23+ public function __construct (int $ maxBufferLength = 8192 )
24+ {
25+ $ this ->maxBufferLength = $ maxBufferLength ;
26+ }
27+
1828 /**
1929 * Emits a response for a PHP SAPI environment.
2030 *
2131 * Emits the status line and headers via the header() function, and the
2232 * body content via the output buffer.
23- *
24- * @param int $maxBufferLength Maximum output buffering size for each iteration
2533 */
26- public function emit (ResponseInterface $ response, int $ maxBufferLength = 8192 ) : bool
34+ public function emit (ResponseInterface $ response ) : bool
2735 {
2836 $ this ->assertNoPreviousOutput ();
2937 $ this ->emitHeaders ($ response );
@@ -32,18 +40,18 @@ public function emit(ResponseInterface $response, int $maxBufferLength = 8192) :
3240 $ range = $ this ->parseContentRange ($ response ->getHeaderLine ('Content-Range ' ));
3341
3442 if (is_array ($ range ) && $ range [0 ] === 'bytes ' ) {
35- $ this ->emitBodyRange ($ range , $ response, $ maxBufferLength );
43+ $ this ->emitBodyRange ($ range , $ response );
3644 return true ;
3745 }
3846
39- $ this ->emitBody ($ response, $ maxBufferLength );
47+ $ this ->emitBody ($ response );
4048 return true ;
4149 }
4250
4351 /**
4452 * Emit the message body.
4553 */
46- private function emitBody (ResponseInterface $ response, int $ maxBufferLength ) : void
54+ private function emitBody (ResponseInterface $ response ) : void
4755 {
4856 $ body = $ response ->getBody ();
4957
@@ -57,14 +65,14 @@ private function emitBody(ResponseInterface $response, int $maxBufferLength) : v
5765 }
5866
5967 while (! $ body ->eof ()) {
60- echo $ body ->read ($ maxBufferLength );
68+ echo $ body ->read ($ this -> maxBufferLength );
6169 }
6270 }
6371
6472 /**
6573 * Emit a range of the message body.
6674 */
67- private function emitBodyRange (array $ range , ResponseInterface $ response, int $ maxBufferLength ) : void
75+ private function emitBodyRange (array $ range , ResponseInterface $ response ) : void
6876 {
6977 list ($ unit , $ first , $ last , $ length ) = $ range ;
7078
@@ -86,7 +94,7 @@ private function emitBodyRange(array $range, ResponseInterface $response, int $m
8694 $ remaining = $ length ;
8795
8896 while ($ remaining >= $ maxBufferLength && ! $ body ->eof ()) {
89- $ contents = $ body ->read ($ maxBufferLength );
97+ $ contents = $ body ->read ($ this -> maxBufferLength );
9098 $ remaining -= strlen ($ contents );
9199
92100 echo $ contents ;
0 commit comments