\Cake\HttpResponseEmitter

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

Summary

Methods
Properties
Constants
emit()
No public properties found
No constants found
emitBody()
emitBodyRange()
emitStatusLine()
emitHeaders()
emitCookies()
flush()
parseContentRange()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

emit()

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

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
$maxBufferLength

emitBody()

emitBody(\Psr\Http\Message\ResponseInterface  $response, integer  $maxBufferLength) : void

Emit the message body.

Parameters

\Psr\Http\Message\ResponseInterface $response

The response to emit

integer $maxBufferLength

The chunk size to emit

emitBodyRange()

emitBodyRange(array  $range, \Psr\Http\Message\ResponseInterface  $response, integer  $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

integer $maxBufferLength

The chunk size to emit

emitStatusLine()

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

emitHeaders()

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

emitCookies()

emitCookies(array  $cookies) : void

Emit cookies using setcookie()

Parameters

array $cookies

An array of Set-Cookie headers.

flush()

flush(integer|null  $maxBufferLevel = null) : void

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

Parameters

integer|null $maxBufferLevel

Flush up to this buffer level.

parseContentRange()

parseContentRange(string  $header) : false|array

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

false|array —

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