ResponseEmitter
in package
implements
EmitterInterface
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
Table of Contents
Interfaces
Properties
- $maxBufferLength : int
- Maximum output buffering size for each iteration.
Methods
- __construct() : mixed
- Constructor
- emit() : bool
- Emit a response.
- emitBody() : void
- Emit the message body.
- emitBodyRange() : void
- Emit a range of the message body.
- emitCookies() : void
- Emit cookies using setcookie()
- emitHeaders() : void
- Emit response headers.
- emitStatusLine() : void
- Emit the status line.
- flush() : void
- Loops through the output buffer, flushing each, before emitting the response.
- parseContentRange() : array<string|int, mixed>|false
- Parse content-range header https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
- setCookie() : bool
- Helper methods to set cookie.
Properties
$maxBufferLength
Maximum output buffering size for each iteration.
protected
int
$maxBufferLength
Methods
__construct()
Constructor
public
__construct([int $maxBufferLength = 8192 ]) : mixed
Parameters
- $maxBufferLength : int = 8192
-
Maximum output buffering size for each iteration.
emit()
Emit a response.
public
emit(ResponseInterface $response) : bool
Emits a response, including status line, headers, and the message body, according to the environment.
Parameters
- $response : ResponseInterface
-
The response to emit.
Return values
boolemitBody()
Emit the message body.
protected
emitBody(ResponseInterface $response) : void
Parameters
- $response : ResponseInterface
-
The response to emit
emitBodyRange()
Emit a range of the message body.
protected
emitBodyRange(array<string|int, mixed> $range, ResponseInterface $response) : void
Parameters
- $range : array<string|int, mixed>
-
The range data to emit
- $response : ResponseInterface
-
The response to emit
emitCookies()
Emit cookies using setcookie()
protected
emitCookies(array<string|int, CookieInterface|string> $cookies) : void
Parameters
- $cookies : array<string|int, CookieInterface|string>
-
An array of cookies.
emitHeaders()
Emit response headers.
protected
emitHeaders(ResponseInterface $response) : void
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
- $response : ResponseInterface
-
The response to emit
emitStatusLine()
Emit the status line.
protected
emitStatusLine(ResponseInterface $response) : void
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
- $response : ResponseInterface
-
The response to emit
flush()
Loops through the output buffer, flushing each, before emitting the response.
protected
flush([int|null $maxBufferLevel = null ]) : void
Parameters
- $maxBufferLevel : int|null = null
-
Flush up to this buffer level.
parseContentRange()
Parse content-range header https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
protected
parseContentRange(string $header) : array<string|int, mixed>|false
Parameters
- $header : string
-
The Content-Range header to parse.
Return values
array<string|int, mixed>|false —[unit, first, last, length]; returns false if no content range or an invalid content range is provided
setCookie()
Helper methods to set cookie.
protected
setCookie(CookieInterface|string $cookie) : bool
Parameters
- $cookie : CookieInterface|string
-
Cookie.