class Response
Response represents an HTTP response.
Properties
| ResponseHeaderBag | $headers | |
| static array | $statusTexts | Status codes translation table. |
Methods
|
__construct(string $content = '', integer $status = 200, array $headers = array())
Constructor. |
||
| static Response |
create(string $content = '', integer $status = 200, array $headers = array())
Factory method for chainability |
|
| string |
__toString()
Returns the Response as an HTTP string. |
|
|
__clone()
Clones the current Response instance. |
||
| Response |
prepare(Request $request)
Prepares the Response before it is sent to the client. |
|
| Response |
sendHeaders()
Sends HTTP headers. |
|
| Response |
sendContent()
Sends content for the current web response. |
|
| Response |
send()
Sends HTTP headers and content. |
|
| Response |
setContent(mixed $content)
Sets the response content. |
|
| string |
getContent()
Gets the current response content. |
|
| Response |
setProtocolVersion(string $version)
Sets the HTTP protocol version (1.0 or 1.1). |
|
| string |
getProtocolVersion()
Gets the HTTP protocol version. |
|
| Response |
setStatusCode(integer $code, mixed $text = null)
Sets the response status code. |
|
| integer |
getStatusCode()
Retrieves the status code for the current web response. |
|
| Response |
setCharset(string $charset)
Sets the response charset. |
|
| string |
getCharset()
Retrieves the response charset. |
|
| Boolean |
isCacheable()
Returns true if the response is worth caching under any circumstance. |
|
| Boolean |
isFresh()
Returns true if the response is "fresh". |
|
| 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. |
|
| Response |
setPrivate()
Marks the response as "private". |
|
| Response |
setPublic()
Marks the response as "public". |
|
| Boolean |
mustRevalidate()
Returns true if the response must be revalidated by caches. |
|
| DateTime |
getDate()
Returns the Date header as a DateTime instance. |
|
| Response |
setDate(DateTime $date)
Sets the Date header. |
|
| integer |
getAge()
Returns the age of the response. |
|
| Response |
expire()
Marks the response stale by setting the Age header to be equal to the maximum age of the response. |
|
| DateTime|null |
getExpires()
Returns the value of the Expires header as a DateTime instance. |
|
| Response |
setExpires(DateTime $date = null)
Sets the Expires HTTP header with a DateTime instance. |
|
| integer|null |
getMaxAge()
Returns the number of seconds after the time specified in the response's Date header when the response should no longer be considered fresh. |
|
| Response |
setMaxAge(integer $value)
Sets the number of seconds after which the response should no longer be considered fresh. |
|
| Response |
setSharedMaxAge(integer $value)
Sets the number of seconds after which the response should no longer be considered fresh by shared caches. |
|
| integer|null |
getTtl()
Returns the response's time-to-live in seconds. |
|
| Response |
setTtl(integer $seconds)
Sets the response's time-to-live for shared caches. |
|
| Response |
setClientTtl(integer $seconds)
Sets the response's time-to-live for private/client caches. |
|
| DateTime|null |
getLastModified()
Returns the Last-Modified HTTP header as a DateTime instance. |
|
| Response |
setLastModified(DateTime $date = null)
Sets the Last-Modified HTTP header with a DateTime instance. |
|
| string|null |
getEtag()
Returns the literal value of the ETag HTTP header. |
|
| Response |
setEtag(string|null $etag = null, Boolean $weak = false)
Sets the ETag value. |
|
| Response |
setCache(array $options)
Sets the response's cache headers (validation and/or expiration). |
|
| Response |
setNotModified()
Modifies the response so that it conforms to the rules defined for a 304 status code. |
|
| Boolean |
hasVary()
Returns true if the response includes a Vary header. |
|
| array |
getVary()
Returns an array of header names given in the Vary header. |
|
| Response |
setVary(string|array $headers, Boolean $replace = true)
Sets the Vary header. |
|
| Boolean |
isNotModified(Request $request)
Determines if the Response validators (ETag, Last-Modified) match a conditional value specified in the Request. |
|
| Boolean |
isInvalid()
Is response invalid? |
|
| Boolean |
isInformational()
Is response informative? |
|
| Boolean |
isSuccessful()
Is response successful? |
|
| Boolean |
isRedirection()
Is the response a redirect? |
|
| Boolean |
isClientError()
Is there a client error? |
|
| Boolean |
isServerError()
Was there a server side error? |
|
| Boolean |
isOk()
Is the response OK? |
|
| Boolean |
isForbidden()
Is the response forbidden? |
|
| Boolean |
isNotFound()
Is the response a not found error? |
|
| Boolean |
isRedirect(string $location = null)
Is the response a redirect of some form? |
|
| Boolean |
isEmpty()
Is the response empty? |
Details
at line 138
public
__construct(string $content = '', integer $status = 200, array $headers = array())
Constructor.
at line 163
static public Response
create(string $content = '', integer $status = 200, array $headers = array())
Factory method for chainability
Example:
return Response::create($body, 200)
->setSharedMaxAge(300);
at line 179
public string
__toString()
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.
at line 190
public
__clone()
Clones the current Response instance.
at line 206
public Response
prepare(Request $request)
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.
at line 266
public Response
sendHeaders()
Sends HTTP headers.
at line 296
public Response
sendContent()
Sends content for the current web response.
at line 310
public Response
send()
Sends HTTP headers and content.
at line 347
public Response
setContent(mixed $content)
Sets the response content.
Valid types are strings, numbers, and objects that implement a __toString() method.
at line 365
public string
getContent()
Gets the current response content.
at line 379
public Response
setProtocolVersion(string $version)
Sets the HTTP protocol version (1.0 or 1.1).
at line 393
public string
getProtocolVersion()
Gets the HTTP protocol version.
at line 413
public Response
setStatusCode(integer $code, mixed $text = null)
Sets the response status code.
at line 444
public integer
getStatusCode()
Retrieves the status code for the current web response.
at line 458
public Response
setCharset(string $charset)
Sets the response charset.
at line 472
public string
getCharset()
Retrieves the response charset.
at line 490
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.
at line 514
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 Expires header and the calculated age is less than the freshness lifetime.
at line 527
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.
at line 541
public Response
setPrivate()
Marks the response as "private".
It makes the response ineligible for serving other clients.
at line 558
public Response
setPublic()
Marks the response as "public".
It makes the response eligible for serving other clients.
at line 578
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.
at line 592
public DateTime
getDate()
Returns the Date header as a DateTime instance.
at line 606
public Response
setDate(DateTime $date)
Sets the Date header.
at line 619
public integer
getAge()
Returns the age of the response.
at line 635
public Response
expire()
Marks the response stale by setting the Age header to be equal to the maximum age of the response.
at line 651
public DateTime|null
getExpires()
Returns the value of the Expires header as a DateTime instance.
at line 672
public Response
setExpires(DateTime $date = null)
Sets the Expires HTTP header with a DateTime instance.
Passing null as value will remove the header.
at line 696
public integer|null
getMaxAge()
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.
at line 724
public Response
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.
at line 742
public Response
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.
at line 762
public integer|null
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.
at line 782
public Response
setTtl(integer $seconds)
Sets the response's time-to-live for shared caches.
This method adjusts the Cache-Control/s-maxage directive.
at line 800
public Response
setClientTtl(integer $seconds)
Sets the response's time-to-live for private/client caches.
This method adjusts the Cache-Control/max-age directive.
at line 816
public DateTime|null
getLastModified()
Returns the Last-Modified HTTP header as a DateTime instance.
at line 832
public Response
setLastModified(DateTime $date = null)
Sets the Last-Modified HTTP header with a DateTime instance.
Passing null as value will remove the header.
at line 852
public string|null
getEtag()
Returns the literal value of the ETag HTTP header.
at line 867
public Response
setEtag(string|null $etag = null, Boolean $weak = false)
Sets the ETag value.
at line 895
public Response
setCache(array $options)
Sets the response's cache headers (validation and/or expiration).
Available options are: etag, last_modified, max_age, s_maxage, private, and public.
at line 948
public Response
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.
at line 968
public Boolean
hasVary()
Returns true if the response includes a Vary header.
at line 980
public array
getVary()
Returns an array of header names given in the Vary header.
at line 999
public Response
setVary(string|array $headers, Boolean $replace = true)
Sets the Vary header.
at line 1019
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.
at line 1048
public Boolean
isInvalid()
Is response invalid?
at line 1060
public Boolean
isInformational()
Is response informative?
at line 1072
public Boolean
isSuccessful()
Is response successful?
at line 1084
public Boolean
isRedirection()
Is the response a redirect?
at line 1096
public Boolean
isClientError()
Is there a client error?
at line 1108
public Boolean
isServerError()
Was there a server side error?
at line 1120
public Boolean
isOk()
Is the response OK?
at line 1132
public Boolean
isForbidden()
Is the response forbidden?
at line 1144
public Boolean
isNotFound()
Is the response a not found error?
at line 1158
public Boolean
isRedirect(string $location = null)
Is the response a redirect of some form?
at line 1170
public Boolean
isEmpty()
Is the response empty?