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).
Namespace: Cake\Http

Method Summary

Method Detail

emit() public

emit(\Psr\Http\Message\ResponseInterface $response, mixed $maxBufferLength)

Emit a response.

Emits a response, including status line, headers, and the message body, according to the environment.

Implementations of this method may be written in such a way as to have side effects, such as usage of header() or pushing output to the output buffer.

Implementations MAY raise exceptions if they are unable to emit the response; e.g., if headers have already been sent.

Parameters

\Psr\Http\Message\ResponseInterface $response

Response

int $maxBufferLength optional

Max buffer length

emitBody() protected

emitBody(\Psr\Http\Message\ResponseInterface $response, mixed $maxBufferLength)

Emit the message body.

Parameters

\Psr\Http\Message\ResponseInterface $response

The response to emit

int $maxBufferLength

The chunk size to emit

emitBodyRange() protected

emitBodyRange(array $range, \Psr\Http\Message\ResponseInterface $response, mixed $maxBufferLength)

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

emitCookies() protected

emitCookies(array $cookies)

Emit cookies using setcookie()

Parameters

array $cookies

An array of Set-Cookie headers.

emitHeaders() protected

emitHeaders(\Psr\Http\Message\ResponseInterface $response)

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

emitStatusLine() protected

emitStatusLine(\Psr\Http\Message\ResponseInterface $response)

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

flush() protected

flush(mixed $maxBufferLevel)

Loops through the output buffer, flushing each, before emitting the response.

Parameters

int|null $maxBufferLevel optional

Flush up to this buffer level.

parseContentRange() protected

parseContentRange(mixed $header)

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

[unit, first, last, length]; returns false if no content range or an invalid content range is provided

setcookie() protected

setcookie(mixed $name, mixed $value, array $options)

Set cookies uses setcookie()

Parameters

string $name

Cookie name.

string $value

Cookie value.

array $options

Cookie options.

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.Http.ResponseEmitter.html