Class ResponseEmitter
Emits a Response to the PHP Server API.
This emitter offers a few changes from the emitters offered by diactoros:
- It logs headers sent using CakePHP's logging tools.
- Cookies are emitted using setcookie() to not conflict with ext/session
- For fastcgi servers with PHP-FPM session_write_close() is called just before fastcgi_finish_request() to make sure session data is saved correctly (especially on slower session backends).
Method Summary
-
emit() public
{@inheritDoc}
-
emitBody() protected
Emit the message body.
-
emitBodyRange() protected
Emit a range of the message body.
-
emitCookies() protected
Emit cookies using setcookie()
-
emitHeaders() protected
Emit response headers.
-
emitStatusLine() protected
Emit the status line.
-
flush() protected
Loops through the output buffer, flushing each, before emitting the response.
-
parseContentRange() protected
Parse content-range header https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
Method Detail
emit() ¶ public
emit(Psr\Http\Message\ResponseInterface $response, int $maxBufferLength = 8192)
{@inheritDoc}
Parameters
-
Psr\Http\Message\ResponseInterface
$response Response
-
int
$maxBufferLength optional Max buffer length
emitBody() ¶ protected
emitBody(Psr\Http\Message\ResponseInterface $response, int $maxBufferLength): void
Emit the message body.
Parameters
-
Psr\Http\Message\ResponseInterface
$response The response to emit
-
int
$maxBufferLength The chunk size to emit
Returns
void
emitBodyRange() ¶ protected
emitBodyRange(array $range, Psr\Http\Message\ResponseInterface $response, int $maxBufferLength): void
Emit a range of the message body.
Parameters
-
array
$range The range data to emit
-
Psr\Http\Message\ResponseInterface
$response The response to emit
-
int
$maxBufferLength The chunk size to emit
Returns
void
emitCookies() ¶ protected
emitCookies(array $cookies): void
Emit cookies using setcookie()
Parameters
-
array
$cookies An array of Set-Cookie headers.
Returns
void
emitHeaders() ¶ protected
emitHeaders(Psr\Http\Message\ResponseInterface $response): void
Emit response headers.
Loops through each header, emitting each; if the header value is an array with multiple values, ensures that each is sent in such a way as to create aggregate headers (instead of replace the previous).
Parameters
-
Psr\Http\Message\ResponseInterface
$response The response to emit
Returns
void
emitStatusLine() ¶ protected
emitStatusLine(Psr\Http\Message\ResponseInterface $response): void
Emit the status line.
Emits the status line using the protocol version and status code from the response; if a reason phrase is available, it, too, is emitted.
Parameters
-
Psr\Http\Message\ResponseInterface
$response The response to emit
Returns
void
flush() ¶ protected
flush(int|null $maxBufferLevel = null): void
Loops through the output buffer, flushing each, before emitting the response.
Parameters
-
int|null
$maxBufferLevel optional Flush up to this buffer level.
Returns
void
parseContentRange() ¶ protected
parseContentRange(string $header): array|false
Parse content-range header https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
Parameters
-
string
$header The Content-Range header to parse.
Returns
array|false