PHP Class Symfony\Component\HttpFoundation\Response

Afficher le fichier Open project: symfony/symfony Class Usage Examples

Méthodes publiques

Свойство 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

Свойство Type Description
$charset string
$content string
$statusCode integer
$statusText string
$version string

Méthodes publiques

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

Méthodes protégées

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

Method Details

__clone() public méthode

Clones the current Response instance.
public __clone ( )

__construct() public méthode

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

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
Résultat string The Response as an HTTP string

closeOutputBuffers() public static méthode

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

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

ensureIEOverSSLCompatibility() protected méthode

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

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

getAge() public méthode

Returns the age of the response.
public getAge ( ) : integer
Résultat integer The age of the response in seconds

getCharset() public méthode

Retrieves the response charset.
public getCharset ( ) : string
Résultat string Character set

getContent() public méthode

Gets the current response content.
public getContent ( ) : string
Résultat string Content

getDate() public méthode

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

getEtag() public méthode

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

getExpires() public méthode

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

getLastModified() public méthode

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

getMaxAge() public méthode

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
Résultat integer | null Number of seconds

getProtocolVersion() public méthode

Gets the HTTP protocol version.
public getProtocolVersion ( ) : string
Résultat string The HTTP protocol version

getStatusCode() public méthode

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

getTtl() public méthode

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
Résultat integer | null The TTL in seconds

getVary() public méthode

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

hasVary() public méthode

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

isCacheable() public méthode

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
Résultat boolean true if the response is worth caching, false otherwise

isClientError() public méthode

Is there a client error?
public isClientError ( ) : boolean
Résultat boolean

isEmpty() public méthode

Is the response empty?
public isEmpty ( ) : boolean
Résultat boolean

isForbidden() public méthode

Is the response forbidden?
public isForbidden ( ) : boolean
Résultat boolean

isFresh() public méthode

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
Résultat boolean true if the response is fresh, false otherwise

isInformational() public méthode

Is response informative?
public isInformational ( ) : boolean
Résultat boolean

isInvalid() public méthode

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

isNotFound() public méthode

Is the response a not found error?
public isNotFound ( ) : boolean
Résultat boolean

isNotModified() public méthode

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
Résultat boolean true if the Response validators match the Request, false otherwise

isOk() public méthode

Is the response OK?
public isOk ( ) : boolean
Résultat boolean

isRedirect() public méthode

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

isRedirection() public méthode

Is the response a redirect?
public isRedirection ( ) : boolean
Résultat boolean

isServerError() public méthode

Was there a server side error?
public isServerError ( ) : boolean
Résultat boolean

isSuccessful() public méthode

Is response successful?
public isSuccessful ( ) : boolean
Résultat boolean

isValidateable() public méthode

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
Résultat boolean true if the response is validateable, false otherwise

mustRevalidate() public méthode

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
Résultat boolean true if the response must be revalidated by a cache, false otherwise

prepare() public méthode

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
Résultat Response The current response

send() public méthode

Sends HTTP headers and content.
public send ( ) : Response
Résultat Response

sendContent() public méthode

Sends content for the current web response.
public sendContent ( ) : Response
Résultat Response

sendHeaders() public méthode

Sends HTTP headers.
public sendHeaders ( ) : Response
Résultat Response

setCache() public méthode

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

setCharset() public méthode

Sets the response charset.
public setCharset ( string $charset ) : Response
$charset string Character set
Résultat Response

setClientTtl() public méthode

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

setContent() public méthode

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

setDate() public méthode

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

setEtag() public méthode

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

setExpires() public méthode

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

setLastModified() public méthode

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

setMaxAge() public méthode

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

setNotModified() public méthode

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

setPrivate() public méthode

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

setProtocolVersion() public méthode

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

setPublic() public méthode

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

setSharedMaxAge() public méthode

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

setStatusCode() public méthode

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.
Résultat Response

setTtl() public méthode

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

setVary() public méthode

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)
Résultat Response

Property Details

$charset protected_oe property

protected string $charset
Résultat string

$content protected_oe property

protected string $content
Résultat string

$headers public_oe property

public ResponseHeaderBag,Symfony\Component\HttpFoundation $headers
Résultat ResponseHeaderBag

$statusCode protected_oe property

protected int $statusCode
Résultat integer

$statusText protected_oe property

protected string $statusText
Résultat 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
Résultat array

$version protected_oe property

protected string $version
Résultat string