Response
class Response
Response represents an HTTP response.
Constants
HTTP_CONTINUE |
|
HTTP_SWITCHING_PROTOCOLS |
|
HTTP_PROCESSING |
|
HTTP_OK |
|
HTTP_CREATED |
|
HTTP_ACCEPTED |
|
HTTP_NON_AUTHORITATIVE_INFORMATION |
|
HTTP_NO_CONTENT |
|
HTTP_RESET_CONTENT |
|
HTTP_PARTIAL_CONTENT |
|
HTTP_MULTI_STATUS |
|
HTTP_ALREADY_REPORTED |
|
HTTP_IM_USED |
|
HTTP_MULTIPLE_CHOICES |
|
HTTP_MOVED_PERMANENTLY |
|
HTTP_FOUND |
|
HTTP_SEE_OTHER |
|
HTTP_NOT_MODIFIED |
|
HTTP_USE_PROXY |
|
HTTP_RESERVED |
|
HTTP_TEMPORARY_REDIRECT |
|
HTTP_PERMANENTLY_REDIRECT |
|
HTTP_BAD_REQUEST |
|
HTTP_UNAUTHORIZED |
|
HTTP_PAYMENT_REQUIRED |
|
HTTP_FORBIDDEN |
|
HTTP_NOT_FOUND |
|
HTTP_METHOD_NOT_ALLOWED |
|
HTTP_NOT_ACCEPTABLE |
|
HTTP_PROXY_AUTHENTICATION_REQUIRED |
|
HTTP_REQUEST_TIMEOUT |
|
HTTP_CONFLICT |
|
HTTP_GONE |
|
HTTP_LENGTH_REQUIRED |
|
HTTP_PRECONDITION_FAILED |
|
HTTP_REQUEST_ENTITY_TOO_LARGE |
|
HTTP_REQUEST_URI_TOO_LONG |
|
HTTP_UNSUPPORTED_MEDIA_TYPE |
|
HTTP_REQUESTED_RANGE_NOT_SATISFIABLE |
|
HTTP_EXPECTATION_FAILED |
|
HTTP_I_AM_A_TEAPOT |
|
HTTP_MISDIRECTED_REQUEST |
|
HTTP_UNPROCESSABLE_ENTITY |
|
HTTP_LOCKED |
|
HTTP_FAILED_DEPENDENCY |
|
HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL |
|
HTTP_UPGRADE_REQUIRED |
|
HTTP_PRECONDITION_REQUIRED |
|
HTTP_TOO_MANY_REQUESTS |
|
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE |
|
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS |
|
HTTP_INTERNAL_SERVER_ERROR |
|
HTTP_NOT_IMPLEMENTED |
|
HTTP_BAD_GATEWAY |
|
HTTP_SERVICE_UNAVAILABLE |
|
HTTP_GATEWAY_TIMEOUT |
|
HTTP_VERSION_NOT_SUPPORTED |
|
HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL |
|
HTTP_INSUFFICIENT_STORAGE |
|
HTTP_LOOP_DETECTED |
|
HTTP_NOT_EXTENDED |
|
HTTP_NETWORK_AUTHENTICATION_REQUIRED |
|
Properties
ResponseHeaderBag | $headers | ||
static array | $statusTexts | Status codes translation table. |
Methods
Constructor.
Factory method for chainability.
Returns the Response as an HTTP string.
Clones the current Response instance.
Sends HTTP headers.
Sends content for the current web response.
Sends HTTP headers and content.
Sets the response content.
Gets the current response content.
Sets the HTTP protocol version (1.0 or 1.1).
Gets the HTTP protocol version.
Sets the response status code.
Retrieves the status code for the current web response.
Sets the response charset.
Retrieves the response charset.
Returns true if the response is worth caching under any circumstance.
Returns true if the response is "fresh".
Returns true if the response includes headers that can be used to validate the response with the origin server using a conditional GET request.
Marks the response as "private".
Marks the response as "public".
Returns true if the response must be revalidated by caches.
Returns the age of the response.
Marks the response stale by setting the Age header to be equal to the maximum age of the response.
Returns the value of the Expires header as a DateTime instance.
Returns the number of seconds after the time specified in the response's Date header when the response should no longer be considered fresh.
Sets the number of seconds after which the response should no longer be considered fresh.
Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
Returns the response's time-to-live in seconds.
Sets the response's time-to-live for shared caches.
Sets the response's time-to-live for private/client caches.
Returns the Last-Modified HTTP header as a DateTime instance.
Returns the literal value of the ETag HTTP header.
Sets the ETag value.
Sets the response's cache headers (validation and/or expiration).
Modifies the response so that it conforms to the rules defined for a 304 status code.
Returns true if the response includes a Vary header.
Returns an array of header names given in the Vary header.
Sets the Vary header.
Determines if the Response validators (ETag, Last-Modified) match a conditional value specified in the Request.
Is response invalid?
Is response informative?
Is response successful?
Is the response a redirect?
Is there a client error?
Was there a server side error?
Is the response OK?
Is the response forbidden?
Is the response a not found error?
Is the response a redirect of some form?
Is the response empty?
Cleans or flushes output buffers up to target level.
Details
at line line 222
__construct(mixed $content = '', int $status = 200, array $headers = array())
Constructor.
at line line 266
static Response
create(mixed $content = '', int $status = 200, array $headers = array())
Factory method for chainability.
Example:
return Response::create($body, 200)
->setSharedMaxAge(300);
at line line 282
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 line 293
__clone()
Clones the current Response instance.
at line line 309
$this
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 line 371
$this
sendHeaders()
Sends HTTP headers.
at line line 410
$this
sendContent()
Sends content for the current web response.
at line line 422
$this
send()
Sends HTTP headers and content.
at line line 447
$this
setContent(mixed $content)
Sets the response content.
Valid types are strings, numbers, null, and objects that implement a __toString() method.
at line line 463
string
getContent()
Gets the current response content.
at line line 475
$this
setProtocolVersion(string $version)
Sets the HTTP protocol version (1.0 or 1.1).
at line line 487
string
getProtocolVersion()
Gets the HTTP protocol version.
at line line 505
$this
setStatusCode(int $code, mixed $text = null)
Sets the response status code.
at line line 534
int
getStatusCode()
Retrieves the status code for the current web response.
at line line 546
$this
setCharset(string $charset)
Sets the response charset.
at line line 558
string
getCharset()
Retrieves the response charset.
at line line 574
bool
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 line 596
bool
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 line 607
bool
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 line 619
$this
setPrivate()
Marks the response as "private".
It makes the response ineligible for serving other clients.
at line line 634
$this
setPublic()
Marks the response as "public".
It makes the response eligible for serving other clients.
at line line 652
bool
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 line 664
DateTime
getDate()
Returns the Date header as a DateTime instance.
at line line 685
$this
setDate(DateTime $date)
Sets the Date header.
at line line 698
int
getAge()
Returns the age of the response.
at line line 712
$this
expire()
Marks the response stale by setting the Age header to be equal to the maximum age of the response.
at line line 726
DateTime|null
getExpires()
Returns the value of the Expires header as a DateTime instance.
at line line 745
$this
setExpires(DateTime $date = null)
Sets the Expires HTTP header with a DateTime instance.
Passing null as value will remove the header.
at line line 767
int|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 line 791
$this
setMaxAge(int $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 line 807
$this
setSharedMaxAge(int $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 line 825
int|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 line 841
$this
setTtl(int $seconds)
Sets the response's time-to-live for shared caches.
This method adjusts the Cache-Control/s-maxage directive.
at line line 857
$this
setClientTtl(int $seconds)
Sets the response's time-to-live for private/client caches.
This method adjusts the Cache-Control/max-age directive.
at line line 871
DateTime|null
getLastModified()
Returns the Last-Modified HTTP header as a DateTime instance.
at line line 885
$this
setLastModified(DateTime $date = null)
Sets the Last-Modified HTTP header with a DateTime instance.
Passing null as value will remove the header.
at line line 903
string|null
getEtag()
Returns the literal value of the ETag HTTP header.
at line line 916
$this
setEtag(string|null $etag = null, bool $weak = false)
Sets the ETag value.
at line line 942
$this
setCache(array $options)
Sets the response's cache headers (validation and/or expiration).
Available options are: etag, lastmodified, maxage, s_maxage, private, and public.
at line line 993
$this
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 line 1011
bool
hasVary()
Returns true if the response includes a Vary header.
at line line 1021
array
getVary()
Returns an array of header names given in the Vary header.
at line line 1043
$this
setVary(string|array $headers, bool $replace = true)
Sets the Vary header.
at line line 1061
bool
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 line 1093
bool
isInvalid()
Is response invalid?
at line line 1103
bool
isInformational()
Is response informative?
at line line 1113
bool
isSuccessful()
Is response successful?
at line line 1123
bool
isRedirection()
Is the response a redirect?
at line line 1133
bool
isClientError()
Is there a client error?
at line line 1143
bool
isServerError()
Was there a server side error?
at line line 1153
bool
isOk()
Is the response OK?
at line line 1163
bool
isForbidden()
Is the response forbidden?
at line line 1173
bool
isNotFound()
Is the response a not found error?
at line line 1185
bool
isRedirect(string $location = null)
Is the response a redirect of some form?
at line line 1195
bool
isEmpty()
Is the response empty?
at line line 1208
static
closeOutputBuffers(int $targetLevel, bool $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.