PHP Class Symfony\Component\HttpFoundation\Response

Datei anzeigen Open project: symfony/symfony Class Usage Examples

Public Properties

Property Type Description
$headers ResponseHeaderBag
$statusTexts array The list of codes is complete according to the {@link http://www.iana.org/assignments/http-status-codes/ Hypertext Transfer Protocol (HTTP) Status Code Registry} (last updated 2016-03-01). Unless otherwise noted, the status code is defined in RFC2616.

Protected Properties

Property Type Description
$charset string
$content string
$statusCode integer
$statusText string
$version string

Public Methods

Method Description
__clone ( ) Clones the current Response instance.
__construct ( mixed $content = '', integer $status = 200, array $headers = [] ) Constructor.
__toString ( ) : string Returns the Response as an HTTP string.
closeOutputBuffers ( integer $targetLevel, boolean $flush ) Cleans or flushes output buffers up to target level.
create ( mixed $content = '', integer $status = 200, array $headers = [] ) : Response Factory method for chainability.
expire ( ) : Response Marks the response stale by setting the Age header to be equal to the maximum age of the response.
getAge ( ) : integer Returns the age of the response.
getCharset ( ) : string Retrieves the response charset.
getContent ( ) : string Gets the current response content.
getDate ( ) : DateTime Returns the Date header as a DateTime instance.
getEtag ( ) : string | null Returns the literal value of the ETag HTTP header.
getExpires ( ) : DateTime | null Returns the value of the Expires header as a DateTime instance.
getLastModified ( ) : DateTime | null Returns the Last-Modified HTTP header as a DateTime instance.
getMaxAge ( ) : integer | null Returns the number of seconds after the time specified in the response's Date header when the response should no longer be considered fresh.
getProtocolVersion ( ) : string Gets the HTTP protocol version.
getStatusCode ( ) : integer Retrieves the status code for the current web response.
getTtl ( ) : integer | null Returns the response's time-to-live in seconds.
getVary ( ) : array Returns an array of header names given in the Vary header.
hasVary ( ) : boolean Returns true if the response includes a Vary header.
isCacheable ( ) : boolean Returns true if the response is worth caching under any circumstance.
isClientError ( ) : boolean Is there a client error?
isEmpty ( ) : boolean Is the response empty?
isForbidden ( ) : boolean Is the response forbidden?
isFresh ( ) : boolean Returns true if the response is "fresh".
isInformational ( ) : boolean Is response informative?
isInvalid ( ) : boolean Is response invalid?
isNotFound ( ) : boolean Is the response a not found error?
isNotModified ( Request $request ) : boolean Determines if the Response validators (ETag, Last-Modified) match a conditional value specified in the Request.
isOk ( ) : boolean Is the response OK?
isRedirect ( string $location = null ) : boolean Is the response a redirect of some form?
isRedirection ( ) : boolean Is the response a redirect?
isServerError ( ) : boolean Was there a server side error?
isSuccessful ( ) : boolean Is response successful?
isValidateable ( ) : boolean Returns true if the response includes headers that can be used to validate the response with the origin server using a conditional GET request.
mustRevalidate ( ) : boolean Returns true if the response must be revalidated by caches.
prepare ( Request $request ) : Response Prepares the Response before it is sent to the client.
send ( ) : Response Sends HTTP headers and content.
sendContent ( ) : Response Sends content for the current web response.
sendHeaders ( ) : Response Sends HTTP headers.
setCache ( array $options ) : Response Sets the response's cache headers (validation and/or expiration).
setCharset ( string $charset ) : Response Sets the response charset.
setClientTtl ( integer $seconds ) : Response Sets the response's time-to-live for private/client caches.
setContent ( mixed $content ) : Response Sets the response content.
setDate ( DateTime $date ) : Response Sets the Date header.
setEtag ( string | null $etag = null, boolean $weak = false ) : Response Sets the ETag value.
setExpires ( DateTime $date = null ) : Response Sets the Expires HTTP header with a DateTime instance.
setLastModified ( DateTime $date = null ) : Response Sets the Last-Modified HTTP header with a DateTime instance.
setMaxAge ( integer $value ) : Response Sets the number of seconds after which the response should no longer be considered fresh.
setNotModified ( ) : Response Modifies the response so that it conforms to the rules defined for a 304 status code.
setPrivate ( ) : Response Marks the response as "private".
setProtocolVersion ( string $version ) : Response Sets the HTTP protocol version (1.0 or 1.1).
setPublic ( ) : Response Marks the response as "public".
setSharedMaxAge ( integer $value ) : Response Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
setStatusCode ( integer $code, mixed $text = null ) : Response Sets the response status code.
setTtl ( integer $seconds ) : Response Sets the response's time-to-live for shared caches.
setVary ( string | array $headers, boolean $replace = true ) : Response Sets the Vary header.

Protected Methods

Method Description
ensureIEOverSSLCompatibility ( Request $request ) Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.

Method Details

__clone() public method

Clones the current Response instance.
public __clone ( )

__construct() public method

Constructor.
public __construct ( mixed $content = '', integer $status = 200, array $headers = [] )
$content mixed The response content, see setContent()
$status integer The response status code
$headers array An array of response headers

__toString() public method

The string representation of the Response is the same as the one that will be sent to the client only if the prepare() method has been called before.
See also: prepare()
public __toString ( ) : string
return string The Response as an HTTP string

closeOutputBuffers() public static method

Resulting level can be greater than target level if a non-removable buffer has been encountered.
public static closeOutputBuffers ( integer $targetLevel, boolean $flush )
$targetLevel integer The target output buffering level
$flush boolean Whether to flush or clean the buffers

create() public static method

Example: return Response::create($body, 200) ->setSharedMaxAge(300);
public static create ( mixed $content = '', integer $status = 200, array $headers = [] ) : Response
$content mixed The response content, see setContent()
$status integer The response status code
$headers array An array of response headers
return Response

ensureIEOverSSLCompatibility() protected method

Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.
See also: http://support.microsoft.com/kb/323308
protected ensureIEOverSSLCompatibility ( Request $request )
$request Request

expire() public method

Marks the response stale by setting the Age header to be equal to the maximum age of the response.
public expire ( ) : Response
return Response

getAge() public method

Returns the age of the response.
public getAge ( ) : integer
return integer The age of the response in seconds

getCharset() public method

Retrieves the response charset.
public getCharset ( ) : string
return string Character set

getContent() public method

Gets the current response content.
public getContent ( ) : string
return string Content

getDate() public method

Returns the Date header as a DateTime instance.
public getDate ( ) : DateTime
return DateTime A \DateTime instance

getEtag() public method

Returns the literal value of the ETag HTTP header.
public getEtag ( ) : string | null
return string | null The ETag HTTP header or null if it does not exist

getExpires() public method

Returns the value of the Expires header as a DateTime instance.
public getExpires ( ) : DateTime | null
return DateTime | null A DateTime instance or null if the header does not exist

getLastModified() public method

Returns the Last-Modified HTTP header as a DateTime instance.
public getLastModified ( ) : DateTime | null
return DateTime | null A DateTime instance or null if the header does not exist

getMaxAge() public method

First, it checks for a s-maxage directive, then a max-age directive, and then it falls back on an expires header. It returns null when no maximum age can be established.
public getMaxAge ( ) : integer | null
return integer | null Number of seconds

getProtocolVersion() public method

Gets the HTTP protocol version.
public getProtocolVersion ( ) : string
return string The HTTP protocol version

getStatusCode() public method

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

getTtl() public method

It returns null when no freshness information is present in the response. When the responses TTL is <= 0, the response may not be served from cache without first revalidating with the origin.
public getTtl ( ) : integer | null
return integer | null The TTL in seconds

getVary() public method

Returns an array of header names given in the Vary header.
public getVary ( ) : array
return array An array of Vary names

hasVary() public method

Returns true if the response includes a Vary header.
public hasVary ( ) : boolean
return boolean true if the response includes a Vary header, false otherwise

isCacheable() public method

Responses marked "private" with an explicit Cache-Control directive are considered uncacheable. Responses with neither a freshness lifetime (Expires, max-age) nor cache validator (Last-Modified, ETag) are considered uncacheable.
public isCacheable ( ) : boolean
return boolean true if the response is worth caching, false otherwise

isClientError() public method

Is there a client error?
public isClientError ( ) : boolean
return boolean

isEmpty() public method

Is the response empty?
public isEmpty ( ) : boolean
return boolean

isForbidden() public method

Is the response forbidden?
public isForbidden ( ) : boolean
return boolean

isFresh() public method

Fresh responses may be served from cache without any interaction with the origin. A response is considered fresh when it includes a Cache-Control/max-age indicator or Expires header and the calculated age is less than the freshness lifetime.
public isFresh ( ) : boolean
return boolean true if the response is fresh, false otherwise

isInformational() public method

Is response informative?
public isInformational ( ) : boolean
return boolean

isInvalid() public method

Is response invalid?
See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
public isInvalid ( ) : boolean
return boolean

isNotFound() public method

Is the response a not found error?
public isNotFound ( ) : boolean
return boolean

isNotModified() public method

If the Response is not modified, it sets the status code to 304 and removes the actual content by calling the setNotModified() method.
public isNotModified ( Request $request ) : boolean
$request Request A Request instance
return boolean true if the Response validators match the Request, false otherwise

isOk() public method

Is the response OK?
public isOk ( ) : boolean
return boolean

isRedirect() public method

Is the response a redirect of some form?
public isRedirect ( string $location = null ) : boolean
$location string
return boolean

isRedirection() public method

Is the response a redirect?
public isRedirection ( ) : boolean
return boolean

isServerError() public method

Was there a server side error?
public isServerError ( ) : boolean
return boolean

isSuccessful() public method

Is response successful?
public isSuccessful ( ) : boolean
return boolean

isValidateable() public method

Returns true if the response includes headers that can be used to validate the response with the origin server using a conditional GET request.
public isValidateable ( ) : boolean
return boolean true if the response is validateable, false otherwise

mustRevalidate() public method

This method indicates that the response must not be served stale by a cache in any circumstance without first revalidating with the origin. When present, the TTL of the response should not be overridden to be greater than the value provided by the origin.
public mustRevalidate ( ) : boolean
return boolean true if the response must be revalidated by a cache, false otherwise

prepare() public method

This method tweaks the Response to ensure that it is compliant with RFC 2616. Most of the changes are based on the Request that is "associated" with this Response.
public prepare ( Request $request ) : Response
$request Request A Request instance
return Response The current response

send() public method

Sends HTTP headers and content.
public send ( ) : Response
return Response

sendContent() public method

Sends content for the current web response.
public sendContent ( ) : Response
return Response

sendHeaders() public method

Sends HTTP headers.
public sendHeaders ( ) : Response
return Response

setCache() public method

Available options are: etag, last_modified, max_age, s_maxage, private, and public.
public setCache ( array $options ) : Response
$options array An array of cache options
return Response

setCharset() public method

Sets the response charset.
public setCharset ( string $charset ) : Response
$charset string Character set
return Response

setClientTtl() public method

This method adjusts the Cache-Control/max-age directive.
public setClientTtl ( integer $seconds ) : Response
$seconds integer Number of seconds
return Response

setContent() public method

Valid types are strings, numbers, null, and objects that implement a __toString() method.
public setContent ( mixed $content ) : Response
$content mixed Content that can be cast to string
return Response

setDate() public method

Sets the Date header.
public setDate ( DateTime $date ) : Response
$date DateTime A \DateTime instance
return Response

setEtag() public method

Sets the ETag value.
public setEtag ( string | null $etag = null, boolean $weak = false ) : Response
$etag string | null The ETag unique identifier or null to remove the header
$weak boolean Whether you want a weak ETag or not
return Response

setExpires() public method

Passing null as value will remove the header.
public setExpires ( DateTime $date = null ) : Response
$date DateTime A \DateTime instance or null to remove the header
return Response

setLastModified() public method

Passing null as value will remove the header.
public setLastModified ( DateTime $date = null ) : Response
$date DateTime A \DateTime instance or null to remove the header
return Response

setMaxAge() public method

This methods sets the Cache-Control max-age directive.
public setMaxAge ( integer $value ) : Response
$value integer Number of seconds
return Response

setNotModified() public method

This sets the status, removes the body, and discards any headers that MUST NOT be included in 304 responses.
See also: http://tools.ietf.org/html/rfc2616#section-10.3.5
public setNotModified ( ) : Response
return Response

setPrivate() public method

It makes the response ineligible for serving other clients.
public setPrivate ( ) : Response
return Response

setProtocolVersion() public method

Sets the HTTP protocol version (1.0 or 1.1).
public setProtocolVersion ( string $version ) : Response
$version string The HTTP protocol version
return Response

setPublic() public method

It makes the response eligible for serving other clients.
public setPublic ( ) : Response
return Response

setSharedMaxAge() public method

This methods sets the Cache-Control s-maxage directive.
public setSharedMaxAge ( integer $value ) : Response
$value integer Number of seconds
return Response

setStatusCode() public method

Sets the response status code.
public setStatusCode ( integer $code, mixed $text = null ) : Response
$code integer HTTP status code
$text mixed HTTP status text If the status text is null it will be automatically populated for the known status codes and left empty otherwise.
return Response

setTtl() public method

This method adjusts the Cache-Control/s-maxage directive.
public setTtl ( integer $seconds ) : Response
$seconds integer Number of seconds
return Response

setVary() public method

Sets the Vary header.
public setVary ( string | array $headers, boolean $replace = true ) : Response
$headers string | array
$replace boolean Whether to replace the actual value or not (true by default)
return Response

Property Details

$charset protected_oe property

protected string $charset
return string

$content protected_oe property

protected string $content
return string

$headers public_oe property

public ResponseHeaderBag,Symfony\Component\HttpFoundation $headers
return ResponseHeaderBag

$statusCode protected_oe property

protected int $statusCode
return integer

$statusText protected_oe property

protected string $statusText
return string

$statusTexts public_oe static_oe property

The list of codes is complete according to the {@link http://www.iana.org/assignments/http-status-codes/ Hypertext Transfer Protocol (HTTP) Status Code Registry} (last updated 2016-03-01). Unless otherwise noted, the status code is defined in RFC2616.
public static array $statusTexts
return array

$version protected_oe property

protected string $version
return string