Class

Symfony\Component\HttpFoundation\RedirectResponse

class RedirectResponse extends Response

RedirectResponse represents an HTTP response doing a redirect.

Properties

ResponseHeaderBag $headers
static $statusTexts

Methods

__construct(string $url, integer $status = 302)

Creates a redirect response so that it conforms to the rules defined for a redirect status code.

string __toString()

Returns the response content as it will be sent (with the headers).

from Response
__clone()

Clones the current Response instance.

from Response
prepare()

Prepares the Response before it is sent to the client.

from Response
sendHeaders()

Sends HTTP headers.

from Response
sendContent()

Sends content for the current web response.

from Response
send()

Sends HTTP headers and content.

from Response
setContent(mixed $content)

Sets the response content.

from Response
string getContent()

Gets the current response content.

from Response
setProtocolVersion(string $version)

Sets the HTTP protocol version (1.0 or 1.1).

from Response
string getProtocolVersion()

Gets the HTTP protocol version.

from Response
setStatusCode(integer $code, mixed $text = null)

Sets the response status code.

from Response
string getStatusCode()

Retrieves the status code for the current web response.

from Response
setCharset(string $charset)

Sets the response charset.

from Response
string getCharset()

Retrieves the response charset.

from Response
Boolean isCacheable()

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

from Response
Boolean isFresh()

Returns true if the response is "fresh".

from Response
Boolean isValidateable()

Returns true if the response includes headers that can be used to validate the response with the origin server using a conditional GET request.

from Response
setPrivate()

Marks the response as "private".

from Response
setPublic()

Marks the response as "public".

from Response
Boolean mustRevalidate()

Returns true if the response must be revalidated by caches.

from Response
DateTime getDate()

Returns the Date header as a DateTime instance.

from Response
setDate(DateTime $date)

Sets the Date header.

from Response
integer getAge()

Returns the age of the response.

from Response
expire()

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

from Response
DateTime getExpires()

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

from Response
setExpires(DateTime $date = null)

Sets the Expires HTTP header with a DateTime instance.

from Response
integer|null getMaxAge()

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.

from Response
setMaxAge(integer $value)

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

from Response
setSharedMaxAge(integer $value)

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

from Response
integer getTtl()

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

from Response
setTtl(integer $seconds)

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

from Response
setClientTtl(integer $seconds)

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

from Response
DateTime getLastModified()

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

from Response
setLastModified(DateTime $date = null)

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

from Response
string getEtag()

Returns the literal value of the ETag HTTP header.

from Response
setEtag(string $etag = null, Boolean $weak = false)

Sets the ETag value.

from Response
setCache(array $options)

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

from Response
setNotModified()

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

from Response
Boolean hasVary()

Returns true if the response includes a Vary header.

from Response
array getVary()

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

from Response
setVary(string|array $headers, Boolean $replace = true)

Sets the Vary header.

from Response
Boolean isNotModified(Request $request)

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

from Response
Boolean isInvalid()

from Response
Boolean isInformational()

from Response
Boolean isSuccessful()

from Response
Boolean isRedirection()

from Response
Boolean isClientError()

from Response
Boolean isServerError()

from Response
Boolean isOk()

from Response
Boolean isForbidden()

from Response
Boolean isNotFound()

from Response
Boolean isRedirect(string $location = null)

from Response
Boolean isEmpty()

from Response

Details

at line 33
public __construct(string $url, integer $status = 302)

Creates a redirect response so that it conforms to the rules defined for a redirect status code.

Parameters

string $url The URL to redirect to
integer $status The status code (302 by default)

See also

http://tools.ietf.org/html/rfc2616#section-10.3

in Response at line 103
public string __toString()

Returns the response content as it will be sent (with the headers).

Return Value

string The response content

in Response at line 116
public __clone()

Clones the current Response instance.

in Response at line 127
public prepare()

Prepares the Response before it is sent to the client.

This method tweaks the Response to ensure that it is compliant with RFC 2616.

in Response at line 151
public sendHeaders()

Sends HTTP headers.

in Response at line 179
public sendContent()

Sends content for the current web response.

in Response at line 189
public send()

Sends HTTP headers and content.

in Response at line 208
public setContent(mixed $content)

Sets the response content.

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

Parameters

mixed $content

in Response at line 224
public string getContent()

Gets the current response content.

Return Value

string Content

in Response at line 236
public setProtocolVersion(string $version)

Sets the HTTP protocol version (1.0 or 1.1).

Parameters

string $version The HTTP protocol version

in Response at line 248
public string getProtocolVersion()

Gets the HTTP protocol version.

Return Value

string The HTTP protocol version

in Response at line 266
public setStatusCode(integer $code, mixed $text = null)

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.

Exceptions

InvalidArgumentException When the HTTP status code is not valid

in Response at line 295
public string getStatusCode()

Retrieves the status code for the current web response.

Return Value

string Status code

in Response at line 307
public setCharset(string $charset)

Sets the response charset.

Parameters

string $charset Character set

in Response at line 319
public string getCharset()

Retrieves the response charset.

Return Value

string Character set

in Response at line 337
public Boolean isCacheable()

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.

Return Value

Boolean true if the response is worth caching, false otherwise

in Response at line 361
public Boolean isFresh()

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 Expiration header and the calculated age is less than the freshness lifetime.

Return Value

Boolean true if the response is fresh, false otherwise

in Response at line 374
public Boolean isValidateable()

Returns true if the response includes headers that can be used to validate the response with the origin server using a conditional GET request.

Return Value

Boolean true if the response is validateable, false otherwise

in Response at line 386
public setPrivate()

Marks the response as "private".

It makes the response ineligible for serving other clients.

in Response at line 399
public setPublic()

Marks the response as "public".

It makes the response eligible for serving other clients.

in Response at line 417
public Boolean mustRevalidate()

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.

Return Value

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

in Response at line 431
public DateTime getDate()

Returns the Date header as a DateTime instance.

Return Value

DateTime A \DateTime instance

Exceptions

RuntimeException When the header is not parseable

in Response at line 443
public setDate(DateTime $date)

Sets the Date header.

Parameters

DateTime $date A \DateTime instance

in Response at line 454
public integer getAge()

Returns the age of the response.

Return Value

integer The age of the response in seconds

in Response at line 468
public expire()

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

in Response at line 482
public DateTime getExpires()

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

Return Value

DateTime A DateTime instance

in Response at line 496
public setExpires(DateTime $date = null)

Sets the Expires HTTP header with a DateTime instance.

If passed a null value, it removes the header.

Parameters

DateTime $date A \DateTime instance

in Response at line 518
public integer|null getMaxAge()

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.

Return Value

integer|null Number of seconds

in Response at line 544
public setMaxAge(integer $value)

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

in Response at line 558
public setSharedMaxAge(integer $value)

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

in Response at line 576
public integer getTtl()

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.

Return Value

integer The TTL in seconds

in Response at line 594
public setTtl(integer $seconds)

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

in Response at line 608
public setClientTtl(integer $seconds)

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

in Response at line 620
public DateTime getLastModified()

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

Return Value

DateTime A DateTime instance

in Response at line 634
public setLastModified(DateTime $date = null)

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

If passed a null value, it removes the header.

Parameters

DateTime $date A \DateTime instance

in Response at line 652
public string getEtag()

Returns the literal value of the ETag HTTP header.

Return Value

string The ETag HTTP header

in Response at line 665
public setEtag(string $etag = null, Boolean $weak = false)

Sets the ETag value.

Parameters

string $etag The ETag unique identifier
Boolean $weak Whether you want a weak ETag or not

in Response at line 687
public setCache(array $options)

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

Available options are: etag, lastmodified, maxage, s_maxage, private, and public.

Parameters

array $options An array of cache options

in Response at line 736
public setNotModified()

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.

See also

http://tools.ietf.org/html/rfc2616#section-10.3.5

in Response at line 754
public Boolean hasVary()

Returns true if the response includes a Vary header.

Return Value

Boolean true if the response includes a Vary header, false otherwise

in Response at line 766
public array getVary()

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

Return Value

array An array of Vary names

in Response at line 783
public setVary(string|array $headers, Boolean $replace = true)

Sets the Vary header.

Parameters

string|array $headers
Boolean $replace Whether to replace the actual value of not (true by default)

in Response at line 801
public Boolean isNotModified(Request $request)

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

Request $request A Request instance

Return Value

Boolean true if the Response validators match the Request, false otherwise

in Response at line 824
public Boolean isInvalid()

Return Value

Boolean

in Response at line 834
public Boolean isInformational()

Return Value

Boolean

in Response at line 844
public Boolean isSuccessful()

Return Value

Boolean

in Response at line 854
public Boolean isRedirection()

Return Value

Boolean

in Response at line 864
public Boolean isClientError()

Return Value

Boolean

in Response at line 874
public Boolean isServerError()

Return Value

Boolean

in Response at line 884
public Boolean isOk()

Return Value

Boolean

in Response at line 894
public Boolean isForbidden()

Return Value

Boolean

in Response at line 904
public Boolean isNotFound()

Return Value

Boolean

in Response at line 916
public Boolean isRedirect(string $location = null)

Parameters

string $location

Return Value

Boolean

in Response at line 926
public Boolean isEmpty()

Return Value

Boolean