HTTP_CONTINUE
HTTP_CONTINUE = 100
Response represents an HTTP response in JSON format.
Note that this class does not force the returned JSON content to be an object. It is however recommended that you do return an object as it protects yourself against XSSI and JSON-JavaScript Hijacking.
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
$headers : \Symfony\Component\HttpFoundation\ResponseHeaderBag
None found |
$statusTexts : array
Status codes translation table.
The list of codes is complete according to the Hypertext Transfer Protocol (HTTP) Status Code Registry (last updated 2016-03-01).
Unless otherwise noted, the status code is defined in RFC2616.
None found |
None found |
None found |
None found |
None found |
None found |
__construct(mixed $data = null, integer $status = 200, array $headers = array(), boolean $json = false)
mixed | $data | The response data |
integer | $status | The response status code |
array | $headers | An array of response headers |
boolean | $json | If the data is already a JSON string |
None found |
create(mixed $data = null, integer $status = 200, array $headers = array()) : static
Factory method for chainability.
Example:
return JsonResponse::create($data, 200)
->setSharedMaxAge(300);
mixed | $data | The json response data |
integer | $status | The response status code |
array | $headers | An array of response headers |
None found |
__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.
The Response as an HTTP string
None found |
None found |
prepare(\Symfony\Component\HttpFoundation\Request $request) : $this
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.
\Symfony\Component\HttpFoundation\Request | $request |
None found |
None found |
None found |
None found |
setContent(mixed $content) : $this
Sets the response content.
Valid types are strings, numbers, null, and objects that implement a __toString() method.
mixed | $content | Content that can be cast to string |
None found |
None found |
setProtocolVersion(string $version) : $this
Sets the HTTP protocol version (1.0 or 1.1).
string | $version | The HTTP protocol version |
final |
since version 3.2 |
---|
getProtocolVersion() : string
Gets the HTTP protocol version.
The HTTP protocol version
final |
since version 3.2 |
---|
setStatusCode(integer $code, mixed $text = null) : $this
Sets the response status code.
If the status text is null it will be automatically populated for the known status codes and left empty otherwise.
integer | $code | HTTP status code |
mixed | $text | HTTP status text |
When the HTTP status code is not valid
final |
since version 3.2 |
---|
getStatusCode() : integer
Retrieves the status code for the current web response.
Status code
final |
since version 3.2 |
---|
setCharset(string $charset) : $this
Sets the response charset.
string | $charset | Character set |
final |
since version 3.2 |
---|
final |
since version 3.2 |
---|
isCacheable() : boolean
Returns true if the response may safely be kept in a shared (surrogate) cache.
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 because there is no way to tell when or how to remove them from the cache.
Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation, for example "status codes that are defined as cacheable by default [...] can be reused by a cache with heuristic expiration unless otherwise indicated" (https://tools.ietf.org/html/rfc7231#section-6.1)
true if the response is worth caching, false otherwise
final |
since version 3.3 |
---|
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.
true if the response is fresh, false otherwise
final |
since version 3.3 |
---|
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.
true if the response is validateable, false otherwise
final |
since version 3.3 |
---|
setPrivate() : $this
Marks the response as "private".
It makes the response ineligible for serving other clients.
final |
since version 3.2 |
---|
setPublic() : $this
Marks the response as "public".
It makes the response eligible for serving other clients.
final |
since version 3.2 |
---|
setImmutable(boolean $immutable = true) : $this
Marks the response as "immutable".
boolean | $immutable | enables or disables the immutable directive |
final |
---|
isImmutable() : boolean
Returns true if the response is marked as "immutable".
returns true if the response is marked as "immutable"; otherwise false
final |
---|
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.
true if the response must be revalidated by a cache, false otherwise
final |
since version 3.3 |
---|
getDate() : \DateTime
Returns the Date header as a DateTime instance.
When the header is not parseable
A \DateTime instance
final |
since version 3.2 |
---|
setDate(\DateTime $date) : $this
Sets the Date header.
\DateTime | $date |
final |
since version 3.2 |
---|
getAge() : integer
Returns the age of the response.
The age of the response in seconds
final |
since version 3.2 |
---|
expire() : $this
Marks the response stale by setting the Age header to be equal to the maximum age of the response.
None found |
getExpires() : \DateTime|null
Returns the value of the Expires header as a DateTime instance.
A DateTime instance or null if the header does not exist
final |
since version 3.2 |
---|
setExpires(\DateTime|null $date = null) : $this
Sets the Expires HTTP header with a DateTime instance.
Passing null as value will remove the header.
\DateTime|null | $date | A \DateTime instance or null to remove the header |
final |
since version 3.2 |
---|
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.
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.
Number of seconds
final |
since version 3.2 |
---|
setMaxAge(integer $value) : $this
Sets the number of seconds after which the response should no longer be considered fresh.
This methods sets the Cache-Control max-age directive.
integer | $value | Number of seconds |
final |
since version 3.2 |
---|
setSharedMaxAge(integer $value) : $this
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.
integer | $value | Number of seconds |
final |
since version 3.2 |
---|
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.
The TTL in seconds
final |
since version 3.2 |
---|
setTtl(integer $seconds) : $this
Sets the response's time-to-live for shared caches.
This method adjusts the Cache-Control/s-maxage directive.
integer | $seconds | Number of seconds |
final |
since version 3.2 |
---|
setClientTtl(integer $seconds) : $this
Sets the response's time-to-live for private/client caches.
This method adjusts the Cache-Control/max-age directive.
integer | $seconds | Number of seconds |
final |
since version 3.2 |
---|
getLastModified() : \DateTime|null
Returns the Last-Modified HTTP header as a DateTime instance.
When the HTTP header is not parseable
A DateTime instance or null if the header does not exist
final |
since version 3.2 |
---|
setLastModified(\DateTime|null $date = null) : $this
Sets the Last-Modified HTTP header with a DateTime instance.
Passing null as value will remove the header.
\DateTime|null | $date | A \DateTime instance or null to remove the header |
final |
since version 3.2 |
---|
getEtag() : string|null
Returns the literal value of the ETag HTTP header.
The ETag HTTP header or null if it does not exist
final |
since version 3.2 |
---|
setEtag(string|null $etag = null, boolean $weak = false) : $this
Sets the ETag value.
string|null | $etag | The ETag unique identifier or null to remove the header |
boolean | $weak | Whether you want a weak ETag or not |
final |
since version 3.2 |
---|
setCache(array $options) : $this
Sets the response's cache headers (validation and/or expiration).
Available options are: etag, last_modified, max_age, s_maxage, private, public and immutable.
array | $options | An array of cache options |
final |
since version 3.3 |
---|
setNotModified() : $this
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.
final |
since version 3.3 |
---|
hasVary() : boolean
Returns true if the response includes a Vary header.
true if the response includes a Vary header, false otherwise
final |
since version 3.2 |
---|
getVary() : array
Returns an array of header names given in the Vary header.
An array of Vary names
final |
since version 3.2 |
---|
setVary(string|array $headers, boolean $replace = true) : $this
Sets the Vary header.
string|array | $headers | |
boolean | $replace | Whether to replace the actual value or not (true by default) |
final |
since version 3.2 |
---|
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.
\Symfony\Component\HttpFoundation\Request | $request |
true if the Response validators match the Request, false otherwise
final |
since version 3.3 |
---|
final |
since version 3.2 |
---|
final |
since version 3.3 |
---|
final |
since version 3.2 |
---|
final |
since version 3.2 |
---|
final |
since version 3.2 |
---|
final |
since version 3.3 |
---|
final |
since version 3.2 |
---|
final |
since version 3.2 |
---|
final |
since version 3.2 |
---|
isRedirect(string $location = null) : boolean
Is the response a redirect of some form?
string | $location |
final |
since version 3.2 |
---|
final |
since version 3.2 |
---|
closeOutputBuffers(integer $targetLevel, boolean $flush)
Cleans or flushes output buffers up to target level.
Resulting level can be greater than target level if a non-removable buffer has been encountered.
integer | $targetLevel | The target output buffering level |
boolean | $flush | Whether to flush or clean the buffers |
final |
since version 3.3 |
---|
fromJsonString( $data = null, $status = 200, $headers = array())
Make easier the creation of JsonResponse from raw json.
$data | ||
$status | ||
$headers |
None found |
setCallback(string|null $callback = null) : $this
Sets the JSONP callback.
string|null | $callback | The JSONP callback or null to use none |
When the callback name is not valid
None found |
setJson(string $json) : $this
Sets a raw string containing a JSON document to be sent.
string | $json |
None found |
setData(mixed $data = array()) : $this
Sets the data to be sent as JSON.
mixed | $data |
None found |
getEncodingOptions() : integer
Returns options used while encoding data to JSON.
None found |
setEncodingOptions(integer $encodingOptions) : $this
Sets options used while encoding data to JSON.
integer | $encodingOptions |
None found |
ensureIEOverSSLCompatibility(\Symfony\Component\HttpFoundation\Request $request)
Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.
\Symfony\Component\HttpFoundation\Request | $request |
final |
since version 3.3 |
---|
update() : $this
Updates the content and headers according to the JSON data and callback.
None found |