Properties

$headers

$headers : \Symfony\Component\HttpFoundation\ResponseHeaderBag

Type

SymfonyComponentHttpFoundationResponseHeaderBag

Tags

None found

$statusTexts

$statusTexts : array

Status codes translation table.

The list of codes is complete according to the Hypertext Transfer Protocol (HTTP) Status Code Registry (last updated 2012-02-13).

Unless otherwise noted, the status code is defined in RFC2616.

Type

array

Tags

None found

$content

$content : string

Type

string

Tags

None found

$version

$version : string

Type

string

Tags

None found

$statusCode

$statusCode : integer

Type

integer

Tags

None found

$statusText

$statusText : string

Type

string

Tags

None found

$charset

$charset : string

Type

string

Tags

None found

Methods

__construct()

__construct(string  $content = '', integer  $status = 200, array  $headers = array()) 

Constructor.

Parameters

string $content

The response content

integer $status

The response status code

array $headers

An array of response headers

Throws

InvalidArgumentException

When the HTTP status code is not valid

Tags

api

create()

create(string  $content = '', integer  $status = 200, array  $headers = array()) : \Symfony\Component\HttpFoundation\Response

Factory method for chainability

Example:

return Response::create($body, 200)
    ->setSharedMaxAge(300);

Parameters

string $content

The response content

integer $status

The response status code

array $headers

An array of response headers

Returns

SymfonyComponentHttpFoundationResponse

static

Tags

None found

__toString()

__toString() : string

Returns the Response as an HTTP string.

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.

Returns

string —

The Response as an HTTP string

See also

Tags

None found

__clone()

__clone() 

Clones the current Response instance.

Tags

None found

prepare()

prepare(\Symfony\Component\HttpFoundation\Request  $request) : \Symfony\Component\HttpFoundation\Response

Prepares the Response before it is sent to the client.

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.

Parameters

SymfonyComponentHttpFoundationRequest $request

A Request instance

Returns

SymfonyComponentHttpFoundationResponse

The current response.

Tags

None found

sendHeaders()

sendHeaders() : \Symfony\Component\HttpFoundation\Response

Sends HTTP headers.

Returns

SymfonyComponentHttpFoundationResponse

Tags

None found

sendContent()

sendContent() : \Symfony\Component\HttpFoundation\Response

Sends content for the current web response.

Returns

SymfonyComponentHttpFoundationResponse

Tags

None found

send()

send() : \Symfony\Component\HttpFoundation\Response

Sends HTTP headers and content.

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

setContent()

setContent(mixed  $content) : \Symfony\Component\HttpFoundation\Response

Sets the response content.

Valid types are strings, numbers, and objects that implement a __toString() method.

Parameters

mixed $content

Throws

UnexpectedValueException

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getContent()

getContent() : string

Gets the current response content.

Returns

string —

Content

Tags

api

setProtocolVersion()

setProtocolVersion(string  $version) : \Symfony\Component\HttpFoundation\Response

Sets the HTTP protocol version (1.0 or 1.1).

Parameters

string $version

The HTTP protocol version

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getProtocolVersion()

getProtocolVersion() : string

Gets the HTTP protocol version.

Returns

string —

The HTTP protocol version

Tags

api

setStatusCode()

setStatusCode(integer  $code, mixed  $text = null) : \Symfony\Component\HttpFoundation\Response

Sets the response status code.

Parameters

integer $code

HTTP status code

mixed $text

HTTP status text

If the status text is null it will be automatically populated for the known status codes and left empty otherwise.

Throws

InvalidArgumentException

When the HTTP status code is not valid

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getStatusCode()

getStatusCode() : integer

Retrieves the status code for the current web response.

Returns

integer —

Status code

Tags

api

setCharset()

setCharset(string  $charset) : \Symfony\Component\HttpFoundation\Response

Sets the response charset.

Parameters

string $charset

Character set

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getCharset()

getCharset() : string

Retrieves the response charset.

Returns

string —

Character set

Tags

api

isCacheable()

isCacheable() : Boolean

Returns true if the response is worth caching under any circumstance.

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.

Returns

Boolean —

true if the response is worth caching, false otherwise

Tags

api

isFresh()

isFresh() : Boolean

Returns true if the response is "fresh".

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.

Returns

Boolean —

true if the response is fresh, false otherwise

Tags

api

isValidateable()

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.

Returns

Boolean —

true if the response is validateable, false otherwise

Tags

api

setPrivate()

setPrivate() : \Symfony\Component\HttpFoundation\Response

Marks the response as "private".

It makes the response ineligible for serving other clients.

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

setPublic()

setPublic() : \Symfony\Component\HttpFoundation\Response

Marks the response as "public".

It makes the response eligible for serving other clients.

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

mustRevalidate()

mustRevalidate() : Boolean

Returns true if the response must be revalidated by caches.

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.

Returns

Boolean —

true if the response must be revalidated by a cache, false otherwise

Tags

api

getDate()

getDate() : \DateTime

Returns the Date header as a DateTime instance.

Throws

RuntimeException

When the header is not parseable

Returns

DateTime —

A DateTime instance

Tags

api

setDate()

setDate(\DateTime  $date) : \Symfony\Component\HttpFoundation\Response

Sets the Date header.

Parameters

DateTime $date

A DateTime instance

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getAge()

getAge() : integer

Returns the age of the response.

Returns

integer —

The age of the response in seconds

Tags

None found

expire()

expire() : \Symfony\Component\HttpFoundation\Response

Marks the response stale by setting the Age header to be equal to the maximum age of the response.

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getExpires()

getExpires() : \DateTime|null

Returns the value of the Expires header as a DateTime instance.

Returns

DateTime|null —

A DateTime instance or null if the header does not exist

Tags

api

setExpires()

setExpires(\DateTime|null  $date = null) : \Symfony\Component\HttpFoundation\Response

Sets the Expires HTTP header with a DateTime instance.

Passing null as value will remove the header.

Parameters

DateTime|null $date

A DateTime instance or null to remove the header

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getMaxAge()

getMaxAge() : integer|null

Returns the number of seconds after the time specified in the response's Date header when the the response should no longer be considered fresh.

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.

Returns

integer|null —

Number of seconds

Tags

api

setMaxAge()

setMaxAge(integer  $value) : \Symfony\Component\HttpFoundation\Response

Sets the number of seconds after which the response should no longer be considered fresh.

This methods sets the Cache-Control max-age directive.

Parameters

integer $value

Number of seconds

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

setSharedMaxAge()

setSharedMaxAge(integer  $value) : \Symfony\Component\HttpFoundation\Response

Sets the number of seconds after which the response should no longer be considered fresh by shared caches.

This methods sets the Cache-Control s-maxage directive.

Parameters

integer $value

Number of seconds

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getTtl()

getTtl() : integer|null

Returns the response's time-to-live in seconds.

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.

Returns

integer|null —

The TTL in seconds

Tags

api

setTtl()

setTtl(integer  $seconds) : \Symfony\Component\HttpFoundation\Response

Sets the response's time-to-live for shared caches.

This method adjusts the Cache-Control/s-maxage directive.

Parameters

integer $seconds

Number of seconds

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

setClientTtl()

setClientTtl(integer  $seconds) : \Symfony\Component\HttpFoundation\Response

Sets the response's time-to-live for private/client caches.

This method adjusts the Cache-Control/max-age directive.

Parameters

integer $seconds

Number of seconds

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getLastModified()

getLastModified() : \DateTime|null

Returns the Last-Modified HTTP header as a DateTime instance.

Throws

RuntimeException

When the HTTP header is not parseable

Returns

DateTime|null —

A DateTime instance or null if the header does not exist

Tags

api

setLastModified()

setLastModified(\DateTime|null  $date = null) : \Symfony\Component\HttpFoundation\Response

Sets the Last-Modified HTTP header with a DateTime instance.

Passing null as value will remove the header.

Parameters

DateTime|null $date

A DateTime instance or null to remove the header

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

getEtag()

getEtag() : string|null

Returns the literal value of the ETag HTTP header.

Returns

string|null —

The ETag HTTP header or null if it does not exist

Tags

api

setEtag()

setEtag(string|null  $etag = null, Boolean  $weak = false) : \Symfony\Component\HttpFoundation\Response

Sets the ETag value.

Parameters

string|null $etag

The ETag unique identifier or null to remove the header

Boolean $weak

Whether you want a weak ETag or not

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

setCache()

setCache(array  $options) : \Symfony\Component\HttpFoundation\Response

Sets the response's cache headers (validation and/or expiration).

Available options are: etag, last_modified, max_age, s_maxage, private, and public.

Parameters

array $options

An array of cache options

Throws

InvalidArgumentException

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

setNotModified()

setNotModified() : \Symfony\Component\HttpFoundation\Response

Modifies the response so that it conforms to the rules defined for a 304 status code.

This sets the status, removes the body, and discards any headers that MUST NOT be included in 304 responses.

Returns

SymfonyComponentHttpFoundationResponse

See also

Tags

api

hasVary()

hasVary() : Boolean

Returns true if the response includes a Vary header.

Returns

Boolean —

true if the response includes a Vary header, false otherwise

Tags

api

getVary()

getVary() : array

Returns an array of header names given in the Vary header.

Returns

array —

An array of Vary names

Tags

api

setVary()

setVary(string|array  $headers, Boolean  $replace = true) : \Symfony\Component\HttpFoundation\Response

Sets the Vary header.

Parameters

string|array $headers
Boolean $replace

Whether to replace the actual value of not (true by default)

Returns

SymfonyComponentHttpFoundationResponse

Tags

api

isNotModified()

isNotModified(\Symfony\Component\HttpFoundation\Request  $request) : Boolean

Determines if the Response validators (ETag, Last-Modified) match a conditional value specified in the Request.

If the Response is not modified, it sets the status code to 304 and removes the actual content by calling the setNotModified() method.

Parameters

SymfonyComponentHttpFoundationRequest $request

A Request instance

Returns

Boolean —

true if the Response validators match the Request, false otherwise

Tags

api

isInvalid()

isInvalid() : Boolean

Is response invalid?

Returns

Boolean

Tags

api

isInformational()

isInformational() : Boolean

Is response informative?

Returns

Boolean

Tags

api

isSuccessful()

isSuccessful() : Boolean

Is response successful?

Returns

Boolean

Tags

api

isRedirection()

isRedirection() : Boolean

Is the response a redirect?

Returns

Boolean

Tags

api

isClientError()

isClientError() : Boolean

Is there a client error?

Returns

Boolean

Tags

api

isServerError()

isServerError() : Boolean

Was there a server side error?

Returns

Boolean

Tags

api

isOk()

isOk() : Boolean

Is the response OK?

Returns

Boolean

Tags

api

isForbidden()

isForbidden() : Boolean

Is the response forbidden?

Returns

Boolean

Tags

api

isNotFound()

isNotFound() : Boolean

Is the response a not found error?

Returns

Boolean

Tags

api

isRedirect()

isRedirect(string  $location = null) : Boolean

Is the response a redirect of some form?

Parameters

string $location

Returns

Boolean

Tags

api

isEmpty()

isEmpty() : Boolean

Is the response empty?

Returns

Boolean

Tags

api