PHP Class sfWebResponse

This class manages web reponses. It supports cookies and headers management.
Author: Fabien Potencier ([email protected])
Inheritance: extends sfResponse
Afficher le fichier Open project: lexpress/symfony1 Class Usage Examples

Protected Properties

Свойство Type Description
$cookies
$headerOnly
$headers
$httpMetas
$javascripts
$metas
$positions
$slots
$statusCode
$statusText
$statusTexts
$stylesheets

Méthodes publiques

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

Méthodes protégées

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

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

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

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

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

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

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

clearHttpHeaders() public méthode

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

clearJavascripts() public méthode

Clear all previously added javascripts
public clearJavascripts ( )

clearStylesheets() public méthode

Clear all previously added stylesheets
public clearStylesheets ( )

copyProperties() public méthode

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

fixContentType() protected méthode

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

getCharset() public méthode

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

getContentType() public méthode

Gets response content type.
public getContentType ( ) : array
Résultat array

getCookies() public méthode

Retrieves cookies from the current web response.
public getCookies ( ) : array
Résultat array Cookies

getDate() public static méthode

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

getHttpHeader() public méthode

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
Résultat string

getHttpHeaders() public méthode

Retrieves HTTP headers from the current web response.
public getHttpHeaders ( ) : string
Résultat string HTTP headers

getHttpMetas() public méthode

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

getJavascripts() public méthode

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
Résultat array An associative array of javascript files as keys and options as values

getMetas() public méthode

Retrieves all meta headers.
public getMetas ( ) : array
Résultat array List of meta headers

getPositions() public méthode

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

getSlots() public méthode

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

getStatusCode() public méthode

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

getStatusText() public méthode

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

getStylesheets() public méthode

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
Résultat array An associative array of stylesheet files as keys and options as values

getTitle() public méthode

Retrieves title for the current web response.
public getTitle ( ) : string
Résultat string Title

hasHttpHeader() public méthode

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

initialize() public méthode

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
Résultat boolean true, if initialization completes successfully, otherwise false

isHeaderOnly() public méthode

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

merge() public méthode

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

normalizeHeaderName() protected méthode

Retrieves a normalized Header.
protected normalizeHeaderName ( string $name ) : string
$name string Header name
Résultat string Normalized header

prependTitle() public méthode

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

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

removeStylesheet() public méthode

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

send() public méthode

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

sendContent() public méthode

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

sendHttpHeaders() public méthode

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

serialize() public méthode

See also: sfResponse
public serialize ( )

setContentType() public méthode

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

setCookie() public méthode

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

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

setHttpHeader() public méthode

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

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

setStatusCode() public méthode

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

setTitle() public méthode

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

See also: sfResponse
public unserialize ( $serialized )

validatePosition() protected méthode

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