PHP Class AppserverIo\Appserver\ServletEngine\Http\Response

Inheritance: implements AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface
Show file Open project: appserver-io/appserver Class Usage Examples

Public Methods

Method Description
addCookie ( AppserverIo\Psr\HttpMessage\CookieInterface $cookie ) : void Adds a cookie.
addHeader ( string $name, string $value, boolean $append = false ) : void Adds a header information got from connection. We've to take care that headers like Set-Cookie header can exist multiple times. To support this create an array that keeps the multiple header values.
appendBodyStream ( string $content ) : void Appends the content.
copyBodyStream ( resource $sourceStream, integer $maxlength = null, integer $offset ) : integer Copies a source stream to body stream.
getBodyContent ( ) : string Return content
getBodyStream ( ) : resource Returns the body stream as a resource.
getCookie ( string $cookieName ) : mixed Returns the cookie with the a cookie
getCookies ( ) : array Returns the cookies.
getException ( ) : Exception | null Returns the exception bound to the response.
getHeader ( string $name ) : mixed Returns header by given name.
getHeaders ( ) : array Returns all headers as array
getHeadersAsString ( ) : string Returns the headers as string
getState ( ) : integer Returns the current state
getStatusCode ( ) : integer Returns the response status code
getStatusReasonPhrase ( ) : string Returns the status phrase based on the status code
getVersion ( ) : string Returns the http version of the response
hasCookie ( string $cookieName ) : boolean Returns TRUE if the response already has a cookie with the passed name, else FALSE.
hasException ( ) : boolean Queries whether the response contains an exception or not.
hasHeader ( string $name ) : boolean Check's if header exists by given name
hasState ( integer $state ) : boolean Compares current state with given state
init ( ) : void Initialises the response object to default properties.
redirect ( string $url, integer $code = 301 ) : void Redirects to the passed URL by adding a 'Location' header and setting the appropriate status code, by default 301.
removeHeader ( string $name ) : void Removes the header with the passed name.
resetBodyStream ( ) : void Reset the body stream
setBodyStream ( resource $bodyStream ) : void Resetss the stream resource pointing to body content.
setException ( Exception $exception ) : void Binds the exception to the response.
setHeaders ( array $headers ) : void Resets all headers by given array
setState ( integer $state ) : void Sets state of response
setStatusCode ( integer $code ) : void Sets the http response status code
setStatusReasonPhrase ( string $statusReasonPhrase ) : void Sets the status reason phrase

Protected Methods

Method Description
initDefaultHeaders ( ) : void Initializes the response with the default headers.

Method Details

addCookie() public method

Adds a cookie.
public addCookie ( AppserverIo\Psr\HttpMessage\CookieInterface $cookie ) : void
$cookie AppserverIo\Psr\HttpMessage\CookieInterface The cookie instance to add
return void

addHeader() public method

Adds a header information got from connection. We've to take care that headers like Set-Cookie header can exist multiple times. To support this create an array that keeps the multiple header values.
public addHeader ( string $name, string $value, boolean $append = false ) : void
$name string The header name
$value string The headers value
$append boolean If TRUE and a header with the passed name already exists, the value will be appended
return void

appendBodyStream() public method

Appends the content.
public appendBodyStream ( string $content ) : void
$content string The content to append
return void

copyBodyStream() public method

Copies a source stream to body stream.
public copyBodyStream ( resource $sourceStream, integer $maxlength = null, integer $offset ) : integer
$sourceStream resource The file pointer to source stream
$maxlength integer The max length to read from source stream
$offset integer The offset from source stream to read
return integer The total number of bytes copied

getBodyContent() public method

Return content
public getBodyContent ( ) : string
return string $content

getBodyStream() public method

Returns the body stream as a resource.
public getBodyStream ( ) : resource
return resource The body stream

getCookie() public method

Returns the cookie with the a cookie
public getCookie ( string $cookieName ) : mixed
$cookieName string Name of the cookie to be checked
return mixed The cookie instance or an array of cookie instances

getCookies() public method

Returns the cookies.
public getCookies ( ) : array
return array The cookies

getException() public method

Returns the exception bound to the response.
public getException ( ) : Exception | null
return Exception | null The exception

getHeader() public method

Returns header by given name.
public getHeader ( string $name ) : mixed
$name string The header name to get
return mixed Usually a string, but can also be an array if we request the Set-Cookie header

getHeaders() public method

Returns all headers as array
public getHeaders ( ) : array
return array

getHeadersAsString() public method

Returns the headers as string
public getHeadersAsString ( ) : string
return string

getState() public method

Returns the current state
public getState ( ) : integer
return integer

getStatusCode() public method

Returns the response status code
public getStatusCode ( ) : integer
return integer

getStatusReasonPhrase() public method

Returns the status phrase based on the status code
public getStatusReasonPhrase ( ) : string
return string

getVersion() public method

Returns the http version of the response
public getVersion ( ) : string
return string

hasCookie() public method

Returns TRUE if the response already has a cookie with the passed name, else FALSE.
public hasCookie ( string $cookieName ) : boolean
$cookieName string Name of the cookie to be checked
return boolean TRUE if the response already has the cookie, else FALSE

hasException() public method

Queries whether the response contains an exception or not.
public hasException ( ) : boolean
return boolean TRUE if an exception has been attached, else FALSE

hasHeader() public method

Check's if header exists by given name
public hasHeader ( string $name ) : boolean
$name string The header name to check
return boolean

hasState() public method

Compares current state with given state
public hasState ( integer $state ) : boolean
$state integer The state to compare with
return boolean Whether state is equal (true) or not (false)

init() public method

Initialises the response object to default properties.
public init ( ) : void
return void

initDefaultHeaders() protected method

Initializes the response with the default headers.
protected initDefaultHeaders ( ) : void
return void

redirect() public method

Redirects to the passed URL by adding a 'Location' header and setting the appropriate status code, by default 301.
public redirect ( string $url, integer $code = 301 ) : void
$url string The URL to forward to
$code integer The status code to set
return void

removeHeader() public method

Removes the header with the passed name.
public removeHeader ( string $name ) : void
$name string Name of the header to remove
return void

resetBodyStream() public method

Reset the body stream
public resetBodyStream ( ) : void
return void

setBodyStream() public method

Resetss the stream resource pointing to body content.
public setBodyStream ( resource $bodyStream ) : void
$bodyStream resource The body content stream resource
return void

setException() public method

Binds the exception to the response.
public setException ( Exception $exception ) : void
$exception Exception The exception to bind.
return void

setHeaders() public method

Resets all headers by given array
public setHeaders ( array $headers ) : void
$headers array The headers array
return void

setState() public method

Sets state of response
public setState ( integer $state ) : void
$state integer The state value
return void

setStatusCode() public method

Sets the http response status code
public setStatusCode ( integer $code ) : void
$code integer The status code to set
return void

setStatusReasonPhrase() public method

Sets the status reason phrase
public setStatusReasonPhrase ( string $statusReasonPhrase ) : void
$statusReasonPhrase string The reason phrase
return void