PHP Interface Aerys\Response

Afficher le fichier Open project: amphp/aerys Interface Usage Examples

Méthodes publiques

Méthode 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 méthode

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

end() public méthode

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 méthode

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 méthode

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
Résultat aerys\Response

setCookie() public méthode

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
Résultat aerys\Response

setHeader() public méthode

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

setReason() public méthode

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

setStatus() public méthode

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

state() public méthode

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

stream() public méthode

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
Résultat Amp\Promise to be succeeded whenever local buffers aren't full