PHP Class sfWebResponse

This class manages web reponses. It supports cookies and headers management.
Author: Fabien Potencier ([email protected])
Inheritance: extends sfResponse
ファイルを表示 Open project: lexpress/symfony1 Class Usage Examples

Protected Properties

Property Type Description
$cookies
$headerOnly
$headers
$httpMetas
$javascripts
$metas
$positions
$slots
$statusCode
$statusText
$statusTexts
$stylesheets

Public Methods

Method Description
addCacheControlHttpHeader ( string $name, string $value = null ) Adds an control cache http header.
addHttpMeta ( string $key, string $value, boolean $replace = true ) Adds a HTTP meta header.
addJavascript ( string $file, string $position = '', string $options = [] ) Adds javascript code to the current web response.
addMeta ( string $key, string $value, boolean $replace = true, boolean $escape = true ) Adds a meta header.
addStylesheet ( string $file, string $position = '', string $options = [] ) Adds a stylesheet to the current web response.
addVaryHttpHeader ( string $header ) Adds vary to a http header.
clearHttpHeaders ( ) Cleans HTTP headers from the current web response.
clearJavascripts ( ) Clear all previously added javascripts
clearStylesheets ( ) Clear all previously added stylesheets
copyProperties ( sfWebResponse $response ) Copies all properties from a given sfWebResponse object to the current one.
getCharset ( ) : string Gets the current charset as defined by the content type.
getContentType ( ) : array Gets response content type.
getCookies ( ) : array Retrieves cookies from the current web response.
getDate ( string $timestamp, string $type = 'rfc1123' ) : string Retrieves a formated date.
getHttpHeader ( string $name, string $default = null ) : string Gets HTTP header current value.
getHttpHeaders ( ) : string Retrieves HTTP headers from the current web response.
getHttpMetas ( ) : string Retrieves meta headers for the current web response.
getJavascripts ( string $position = self::ALL ) : array Retrieves javascript files from the current web response.
getMetas ( ) : array Retrieves all meta headers.
getPositions ( ) : array Returns the available position names for stylesheets and javascripts in order.
getSlots ( ) : string Retrieves slots from the current web response.
getStatusCode ( ) : integer Retrieves status code for the current web response.
getStatusText ( ) : string Retrieves status text for the current web response.
getStylesheets ( string $position = self::ALL ) : array Retrieves stylesheets for the current web response.
getTitle ( ) : string Retrieves title for the current web response.
hasHttpHeader ( string $name ) : boolean Checks if response has given HTTP header.
initialize ( sfEventDispatcher $dispatcher, array $options = [] ) : boolean Initializes this sfWebResponse.
isHeaderOnly ( ) : boolean Returns if the response must only consist of HTTP headers.
merge ( sfWebResponse $response ) Merges all properties from a given sfWebResponse object to the current one.
prependTitle ( string $title, string $separator = ' - ', boolean $escape = true ) Preprend title
removeJavascript ( string $file ) Removes a JavaScript file from the current web response.
removeStylesheet ( string $file ) Removes a stylesheet from the current web response.
send ( ) Sends the HTTP headers and the content.
sendContent ( ) Send content for the current web response.
sendHttpHeaders ( ) Sends HTTP headers and cookies. Only the first invocation of this method will send the headers.
serialize ( )
setContentType ( string $value ) Sets response content type.
setCookie ( string $name, string $value, string $expire = null, string $path = '/', string $domain = '', boolean $secure = false, boolean $httpOnly = false ) Sets a cookie.
setHeaderOnly ( boolean $value = true ) Sets if the response consist of just HTTP headers.
setHttpHeader ( string $name, string $value, boolean $replace = true ) Sets a HTTP header.
setSlot ( string $name, string $content ) Sets a slot content.
setStatusCode ( string $code, string $name = null ) Sets response status code.
setTitle ( string $title, boolean $escape = true ) Sets title for the current web response.
unserialize ( $serialized )

Protected Methods

Method Description
fixContentType ( string $contentType ) : string Fixes the content type by adding the charset for text content types.
normalizeHeaderName ( string $name ) : string Retrieves a normalized Header.
validatePosition ( string $position ) Validate a position name.

Method Details

addCacheControlHttpHeader() public method

Adds an control cache http header.
public addCacheControlHttpHeader ( string $name, string $value = null )
$name string HTTP header
$value string Value for the http header

addHttpMeta() public method

Adds a HTTP meta header.
public addHttpMeta ( string $key, string $value, boolean $replace = true )
$key string Key to replace
$value string HTTP meta header value (if null, remove the HTTP meta)
$replace boolean Replace or not

addJavascript() public method

Adds javascript code to the current web response.
public addJavascript ( string $file, string $position = '', string $options = [] )
$file string The JavaScript file
$position string Position
$options string Javascript options

addMeta() public method

Adds a meta header.
public addMeta ( string $key, string $value, boolean $replace = true, boolean $escape = true )
$key string Name of the header
$value string Meta header value (if null, remove the meta)
$replace boolean true if it's replaceable
$escape boolean true for escaping the header

addStylesheet() public method

Adds a stylesheet to the current web response.
public addStylesheet ( string $file, string $position = '', string $options = [] )
$file string The stylesheet file
$position string Position
$options string Stylesheet options

addVaryHttpHeader() public method

Adds vary to a http header.
public addVaryHttpHeader ( string $header )
$header string HTTP header

clearHttpHeaders() public method

Cleans HTTP headers from the current web response.
public clearHttpHeaders ( )

clearJavascripts() public method

Clear all previously added javascripts
public clearJavascripts ( )

clearStylesheets() public method

Clear all previously added stylesheets
public clearStylesheets ( )

copyProperties() public method

Copies all properties from a given sfWebResponse object to the current one.
public copyProperties ( sfWebResponse $response )
$response sfWebResponse An sfWebResponse instance

fixContentType() protected method

Fixes the content type by adding the charset for text content types.
protected fixContentType ( string $contentType ) : string
$contentType string The content type
return string The content type with the charset if needed

getCharset() public method

Gets the current charset as defined by the content type.
public getCharset ( ) : string
return string The current charset

getContentType() public method

Gets response content type.
public getContentType ( ) : array
return array

getCookies() public method

Retrieves cookies from the current web response.
public getCookies ( ) : array
return array Cookies

getDate() public static method

Retrieves a formated date.
public static getDate ( string $timestamp, string $type = 'rfc1123' ) : string
$timestamp string Timestamp
$type string Format type
return string Formatted date

getHttpHeader() public method

Gets HTTP header current value.
public getHttpHeader ( string $name, string $default = null ) : string
$name string HTTP header name
$default string Default value returned if named HTTP header is not found
return string

getHttpHeaders() public method

Retrieves HTTP headers from the current web response.
public getHttpHeaders ( ) : string
return string HTTP headers

getHttpMetas() public method

Retrieves meta headers for the current web response.
public getHttpMetas ( ) : string
return string Meta headers

getJavascripts() public method

By default, the position is sfWebResponse::ALL, and the method returns all javascripts ordered by position.
public getJavascripts ( string $position = self::ALL ) : array
$position string The position
return array An associative array of javascript files as keys and options as values

getMetas() public method

Retrieves all meta headers.
public getMetas ( ) : array
return array List of meta headers

getPositions() public method

Returns the available position names for stylesheets and javascripts in order.
public getPositions ( ) : array
return array An array of position names

getSlots() public method

Retrieves slots from the current web response.
public getSlots ( ) : string
return string Javascript code

getStatusCode() public method

Retrieves status code for the current web response.
public getStatusCode ( ) : integer
return integer Status code

getStatusText() public method

Retrieves status text for the current web response.
public getStatusText ( ) : string
return string Status text

getStylesheets() public method

By default, the position is sfWebResponse::ALL, and the method returns all stylesheets ordered by position.
public getStylesheets ( string $position = self::ALL ) : array
$position string The position
return array An associative array of stylesheet files as keys and options as values

getTitle() public method

Retrieves title for the current web response.
public getTitle ( ) : string
return string Title

hasHttpHeader() public method

Checks if response has given HTTP header.
public hasHttpHeader ( string $name ) : boolean
$name string HTTP header name
return boolean

initialize() public method

Available options: * charset: The charset to use (utf-8 by default) * content_type: The content type (text/html by default) * send_http_headers: Whether to send HTTP headers or not (true by default) * http_protocol: The HTTP protocol to use for the response (HTTP/1.0 by default)
See also: sfResponse
public initialize ( sfEventDispatcher $dispatcher, array $options = [] ) : boolean
$dispatcher sfEventDispatcher An sfEventDispatcher instance
$options array An array of options
return boolean true, if initialization completes successfully, otherwise false

isHeaderOnly() public method

Returns if the response must only consist of HTTP headers.
public isHeaderOnly ( ) : boolean
return boolean returns true if, false otherwise

merge() public method

Merges all properties from a given sfWebResponse object to the current one.
public merge ( sfWebResponse $response )
$response sfWebResponse An sfWebResponse instance

normalizeHeaderName() protected method

Retrieves a normalized Header.
protected normalizeHeaderName ( string $name ) : string
$name string Header name
return string Normalized header

prependTitle() public method

Preprend title
public prependTitle ( string $title, string $separator = ' - ', boolean $escape = true )
$title string Title name
$separator string Separator string (default: " - ")
$escape boolean true, for escaping the title

removeJavascript() public method

Removes a JavaScript file from the current web response.
public removeJavascript ( string $file )
$file string The Javascript file to remove

removeStylesheet() public method

Removes a stylesheet from the current web response.
public removeStylesheet ( string $file )
$file string The stylesheet file to remove

send() public method

Sends the HTTP headers and the content.
public send ( )

sendContent() public method

Send content for the current web response.
public sendContent ( )

sendHttpHeaders() public method

Subsequent invocations will silently do nothing. This allows certain actions to send headers early, while still using the standard controller.
public sendHttpHeaders ( )

serialize() public method

See also: sfResponse
public serialize ( )

setContentType() public method

Sets response content type.
public setContentType ( string $value )
$value string Content type

setCookie() public method

Sets a cookie.
public setCookie ( string $name, string $value, string $expire = null, string $path = '/', string $domain = '', boolean $secure = false, boolean $httpOnly = false )
$name string HTTP header name
$value string Value for the cookie
$expire string Cookie expiration period
$path string Path
$domain string Domain name
$secure boolean If secure
$httpOnly boolean If uses only HTTP

setHeaderOnly() public method

Sets if the response consist of just HTTP headers.
public setHeaderOnly ( boolean $value = true )
$value boolean

setHttpHeader() public method

Sets a HTTP header.
public setHttpHeader ( string $name, string $value, boolean $replace = true )
$name string HTTP header name
$value string Value (if null, remove the HTTP header)
$replace boolean Replace for the value

setSlot() public method

Sets a slot content.
public setSlot ( string $name, string $content )
$name string Slot name
$content string Content

setStatusCode() public method

Sets response status code.
public setStatusCode ( string $code, string $name = null )
$code string HTTP status code
$name string HTTP status text

setTitle() public method

Sets title for the current web response.
public setTitle ( string $title, boolean $escape = true )
$title string Title name
$escape boolean true, for escaping the title

unserialize() public method

See also: sfResponse
public unserialize ( $serialized )

validatePosition() protected method

Validate a position name.
protected validatePosition ( string $position )
$position string

Property Details

$cookies protected_oe property

protected $cookies

$headerOnly protected_oe property

protected $headerOnly

$headers protected_oe property

protected $headers

$httpMetas protected_oe property

protected $httpMetas

$javascripts protected_oe property

protected $javascripts

$metas protected_oe property

protected $metas

$positions protected_oe property

protected $positions

$slots protected_oe property

protected $slots

$statusCode protected_oe property

protected $statusCode

$statusText protected_oe property

protected $statusText

$statusTexts protected_oe static_oe property

protected static $statusTexts

$stylesheets protected_oe property

protected $stylesheets