PHP Interface Aerys\Response

Datei anzeigen Open project: amphp/aerys Interface Usage Examples

Public Methods

Method Description
addHeader ( string $field, string $value ) : aerys\Response Append the specified header
end ( string $finalBodyChunk = null ) Signify the end of streaming response output
flush ( ) Request that buffered stream data be flushed to the client
push ( string $url, array $headers = null ) : aerys\Response Indicate resources which a client likely needs to fetch. (e.g. Link: preload or HTTP/2 Server Push)
setCookie ( string $name, string $value, array $flags = [] ) : aerys\Response Provides an easy API to set cookie headers Those who prefer using addHeader() may do so.
setHeader ( string $field, string $value ) : aerys\Response Set the specified header
setReason ( string $phrase ) : aerys\Response Set the optional HTTP reason phrase
setStatus ( integer $code ) : aerys\Response Set the numeric HTTP status code
state ( ) : integer Retrieve the current response state
stream ( string $partialBodyChunk ) : Amp\Promise Incrementally stream parts of the response entity body

Method Details

addHeader() public method

Append the specified header
public addHeader ( string $field, string $value ) : aerys\Response
$field string
$value string
return aerys\Response

end() public method

User applications are NOT required to call Response::end() after streaming or sending response data (though it's not incorrect to do so) -- the server will automatically call end() as needed. Passing the optional $finalBodyChunk parameter is a shortcut equivalent to the following: $response->stream($finalBodyChunk); $response->end(); Note: Invoking Response::end() with a non-empty $finalBodyChunk parameter without having previously invoked Response::stream() is equivalent to calling Response::send($finalBodyChunk).
public end ( string $finalBodyChunk = null )
$finalBodyChunk string Optional final body data to send

flush() public method

This method only makes sense when streaming output via Response::stream(). Invoking it before calling stream() or after end() is a logic error.
public flush ( )

push() public method

Indicate resources which a client likely needs to fetch. (e.g. Link: preload or HTTP/2 Server Push)
public push ( string $url, array $headers = null ) : aerys\Response
$url string The URL this request should be dispatched to
$headers array Optional custom headers, else the server will try to reuse headers from the last request
return aerys\Response

setCookie() public method

Provides an easy API to set cookie headers Those who prefer using addHeader() may do so.
public setCookie ( string $name, string $value, array $flags = [] ) : aerys\Response
$name string
$value string
$flags array Shall be an array of key => value pairs and/or unkeyed values as per https://tools.ietf.org/html/rfc6265#section-5.2.1
return aerys\Response

setHeader() public method

This method will replace any existing headers for the specified field.
public setHeader ( string $field, string $value ) : aerys\Response
$field string
$value string
return aerys\Response

setReason() public method

Set the optional HTTP reason phrase
public setReason ( string $phrase ) : aerys\Response
$phrase string A human readable string describing the status code
return aerys\Response

setStatus() public method

If not assigned this value defaults to 200.
public setStatus ( integer $code ) : aerys\Response
$code integer An integer in the range [100-599]
return aerys\Response

state() public method

The response state is a bitmask of the following flags: - Response::NONE - Response::STARTED - Response::STREAMING - Response::ENDED
public state ( ) : integer
return integer

stream() public method

This method may be repeatedly called to stream the response body. Applications that can afford to buffer an entire response in memory or can wait for all body data to generate may use Response::end() to output the entire response in a single call. Note: Headers are sent upon the first invocation of Response::stream().
public stream ( string $partialBodyChunk ) : Amp\Promise
$partialBodyChunk string A portion of the response entity body
return Amp\Promise to be succeeded whenever local buffers aren't full