SapiEmitter
extends ResponseEmitterAbstract
in package
Table of Contents
Properties
- $body : StreamInterface
- $bufferSize : int
- $hasContentRange : bool
- $hasCustomLength : bool
- $rangeLength : int
- $rangeStart : int
- $response : ResponseInterface
Methods
- __construct() : mixed
- ResponseEmitter constructor
- emit() : void
- Emits a PSR-7 response.
- emitBody() : void
- emits the body of the given response with respect to the parameters given in content-range and content-length headers
- emitBodyRange() : void
- emits a part of the body
- emitBuffer() : void
- emits the given buffer
- emitHeaders() : void
- Emits the headers
- getStatusLine() : string
- Returns a full status line for the given response, e.g. "HTTP/1.1 200 OK"
- hasBody() : bool
- Checks whether the response has (or is supposed to have) a body
- parseContentRange() : array{0: int, 1: int, 2: int|null, 3: int}|null
- sendHeader() : void
- Allow to intercept header calls in tests
- setContentLengthHeader() : void
- Sets/adjusts the Content-Length header
Properties
$body
protected
StreamInterface
$body
$bufferSize
protected
int
$bufferSize
= 65536
$hasContentRange
protected
bool
$hasContentRange
$hasCustomLength
protected
bool
$hasCustomLength
$rangeLength
protected
int
$rangeLength
= 0
$rangeStart
protected
int
$rangeStart
= 0
$response
protected
ResponseInterface
$response
Methods
__construct()
ResponseEmitter constructor
public
__construct(ResponseInterface $response[, int $bufferSize = 65536 ]) : mixed
Parameters
- $response : ResponseInterface
- $bufferSize : int = 65536
emit()
Emits a PSR-7 response.
public
emit() : void
emitBody()
emits the body of the given response with respect to the parameters given in content-range and content-length headers
protected
emitBody() : void
emitBodyRange()
emits a part of the body
protected
emitBodyRange(int $start, int $length) : void
Parameters
- $start : int
- $length : int
emitBuffer()
emits the given buffer
protected
emitBuffer(string $buffer) : void
Parameters
- $buffer : string
Tags
emitHeaders()
Emits the headers
protected
emitHeaders() : void
There are two special-case header calls. The first is a header that starts with the string "HTTP/" (case is not significant), which will be used to figure out the HTTP status code to send. For example, if you have configured Apache to use a PHP script to handle requests for missing files (using the ErrorDocument directive), you may want to make sure that your script generates the proper status code.
The second special case is the "Location:" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless the 201 or a 3xx status code has already been set.
Tags
getStatusLine()
Returns a full status line for the given response, e.g. "HTTP/1.1 200 OK"
protected
getStatusLine() : string
Return values
stringhasBody()
Checks whether the response has (or is supposed to have) a body
protected
hasBody() : bool
Tags
Return values
boolparseContentRange()
protected
parseContentRange() : array{0: int, 1: int, 2: int|null, 3: int}|null
Tags
Return values
array{0: int, 1: int, 2: int|null, 3: int}|nullsendHeader()
Allow to intercept header calls in tests
protected
sendHeader(string $header, bool $replace[, int $response_code = 0 ]) : void
Parameters
- $header : string
- $replace : bool
- $response_code : int = 0
Tags
setContentLengthHeader()
Sets/adjusts the Content-Length header
protected
setContentLengthHeader() : void
(technically we could do this in a PSR-15 middleware but this class is supposed to work as standalone as well)