PHP Class Bluz\Response\Response

Author: Anton Shevchuk
Inheritance: use trait Bluz\Common\Options
Datei anzeigen Open project: bluzphp/framework Class Usage Examples

Protected Properties

Property Type Description
$body result can be Controller|Layout
$code response code equal to HTTP status codes
$cookies list of cookies
$headers list of headers
$phrase HTTP Phrase
$protocol HTTP protocol version
$type CLI|HTML|JSON

Public Methods

Method Description
addHeader ( string $header, string $value ) : void Appends a header value for the specified header
addHeaders ( array $headers ) : void Merges in an associative array of headers.
clearBody ( ) : void Clear response body
getBody ( ) : Controller | Bluz\Layout\Layout Get response body
getCookie ( string $name ) : array | null Get Cookie by name
getHeader ( string $header ) : string Retrieve a header by the given case-insensitive name as a string
getHeaderAsArray ( string $header ) : string[] Retrieves a header by the given case-insensitive name as an array of strings
getHeaders ( ) : array Gets all message headers
getProtocolVersion ( ) : string Gets the HTTP protocol version as a string
getReasonPhrase ( ) : string | null Gets the response Reason-Phrase, a short textual description of the Status-Code
getStatusCode ( ) : integer Gets the response Status-Code
hasHeader ( string $header ) : boolean Checks if a header exists by the given case-insensitive name
removeHeader ( string $header ) : void Remove a specific header by case-insensitive name.
removeHeaders ( ) : void Remove all headers
send ( ) send
setBody ( mixed $body ) : void Set response body
setCookie ( string $name, string $value = '', integer | string | DateTime $expire, string $path = '/', string $domain = '', boolean $secure = false, boolean $httpOnly = false ) : void Set Cookie
setHeader ( string $header, string | string[] $value ) : void Sets a header, replacing any existing values of any headers with the same case-insensitive name
setHeaders ( array $headers ) : void Sets headers, replacing any headers that have already been set on the message
setReasonPhrase ( string $phrase ) Sets the Reason-Phrase of the response
setStatusCode ( integer $code ) : void Sets the status code of this response
switchType ( $type ) Set Response Type, one of JSON, HTML or CLI

Protected Methods

Method Description
sendCookies ( ) : void Process Cookies to Header

Method Details

addHeader() public method

Existing values for the specified header will be maintained. The new value will be appended to the existing list.
public addHeader ( string $header, string $value ) : void
$header string header name to add
$value string value of the header
return void

addHeaders() public method

Each array key MUST be a string representing the case-insensitive name of a header. Each value MUST be either a string or an array of strings. For each value, the value is appended to any existing header of the same name, or, if a header does not already exist by the given name, then the header is added.
public addHeaders ( array $headers ) : void
$headers array Associative array of headers to add to the message
return void

clearBody() public method

Clear response body
public clearBody ( ) : void
return void

getBody() public method

Get response body
public getBody ( ) : Controller | Bluz\Layout\Layout
return Bluz\Controller\Controller | Bluz\Layout\Layout

getCookie() public method

Get Cookie by name
public getCookie ( string $name ) : array | null
$name string
return array | null

getHeader() public method

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.
public getHeader ( string $header ) : string
$header string case-insensitive header name.
return string

getHeaderAsArray() public method

Retrieves a header by the given case-insensitive name as an array of strings
public getHeaderAsArray ( string $header ) : string[]
$header string Case-insensitive header name.
return string[]

getHeaders() public method

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header. Represent the headers as a string foreach ($message->getHeaders() as $name => $values) { echo $name . ": " . implode(", ", $values); }
public getHeaders ( ) : array
return array returns an associative array of the message's headers.

getProtocolVersion() public method

The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
public getProtocolVersion ( ) : string
return string HTTP protocol version.

getReasonPhrase() public method

Because a Reason-Phrase is not a required element in response Status-Line, the Reason-Phrase value MAY be null. Implementations MAY choose to return the default RFC 2616 recommended reason phrase for the response's Status-Code.
public getReasonPhrase ( ) : string | null
return string | null reason phrase, or null if unknown.

getStatusCode() public method

The Status-Code is a 3-digit integer result code of the server's attempt to understand and satisfy the request.
public getStatusCode ( ) : integer
return integer status code.

hasHeader() public method

Checks if a header exists by the given case-insensitive name
public hasHeader ( string $header ) : boolean
$header string case-insensitive header name.
return boolean returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.

removeHeader() public method

Remove a specific header by case-insensitive name.
public removeHeader ( string $header ) : void
$header string HTTP header to remove
return void

removeHeaders() public method

Remove all headers
public removeHeaders ( ) : void
return void

send() public method

send
public send ( )

sendCookies() protected method

Set-Cookie: =[; =]... [; expires=][; domain=] [; path=][; secure][; httponly]
protected sendCookies ( ) : void
return void

setBody() public method

Set response body
public setBody ( mixed $body ) : void
$body mixed
return void

setCookie() public method

Set Cookie
public setCookie ( string $name, string $value = '', integer | string | DateTime $expire, string $path = '/', string $domain = '', boolean $secure = false, boolean $httpOnly = false ) : void
$name string
$value string
$expire integer | string | DateTime
$path string
$domain string
$secure boolean
$httpOnly boolean
return void

setHeader() public method

The header name is case-insensitive. The header values MUST be a string or an array of strings.
public setHeader ( string $header, string | string[] $value ) : void
$header string header name
$value string | string[] header value(s)
return void

setHeaders() public method

The array keys MUST be a string. The array values must be either a string or an array of strings.
public setHeaders ( array $headers ) : void
$headers array Headers to set.
return void

setReasonPhrase() public method

If no Reason-Phrase is specified, implementations MAY choose to default to the RFC 2616 recommended reason phrase for the response's Status-Code.
public setReasonPhrase ( string $phrase )
$phrase string the Reason-Phrase to set.

setStatusCode() public method

Sets the status code of this response
public setStatusCode ( integer $code ) : void
$code integer the 3-digit integer result code to set.
return void

switchType() public method

Set Response Type, one of JSON, HTML or CLI
public switchType ( $type )
$type

Property Details

$body protected_oe property

result can be Controller|Layout
protected $body

$code protected_oe property

response code equal to HTTP status codes
protected $code

$cookies protected_oe property

list of cookies
protected $cookies

$headers protected_oe property

list of headers
protected $headers

$phrase protected_oe property

HTTP Phrase
protected $phrase

$protocol protected_oe property

HTTP protocol version
protected $protocol

$type protected_oe property

CLI|HTML|JSON
protected $type