Methods summary
public
|
#
__construct( string $content = '', integer $status = 200, array $headers = array() )
Constructor.
Parameters
- $content
string $content The response content
- $status
integer $status The response status code
- $headers
array $headers An array of response headers
Throws
Api
|
public static
Symfony\Component\HttpFoundation\Response
|
#
create( string $content = '', integer $status = 200, array $headers = array() )
Factory method for chainability
Factory method for chainability
Example:
return Response::create($body, 200) ->setSharedMaxAge(300);
Parameters
- $content
string $content The response content
- $status
integer $status The response status code
- $headers
array $headers An array of response headers
Returns
|
public
string
|
#
__toString( )
Returns the Response as an HTTP 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
|
public
|
#
__clone( )
Clones the current Response instance.
Clones the current Response instance.
|
public
Symfony\Component\HttpFoundation\Response
|
#
prepare( Symfony\Component\HttpFoundation\Request $request )
Prepares the Response before it is sent to the client.
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
Returns
|
public
Symfony\Component\HttpFoundation\Response
|
#
sendContent( )
Sends content for the current web response.
Sends content for the current web response.
Returns
|
public
Symfony\Component\HttpFoundation\Response
|
#
send( )
Sends HTTP headers and content.
Sends HTTP headers and content.
Returns
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setContent( mixed $content )
Sets the response content.
Sets the response content.
Valid types are strings, numbers, and objects that implement a __toString()
method.
Parameters
Returns
Throws
Api
|
public
string
|
#
getContent( )
Gets the current response content.
Gets the current response content.
Returns
string Content
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setProtocolVersion( string $version )
Sets the HTTP protocol version (1.0 or 1.1).
Sets the HTTP protocol version (1.0 or 1.1).
Parameters
- $version
string $version The HTTP protocol version
Returns
Api
|
public
string
|
#
getProtocolVersion( )
Gets the HTTP protocol version.
Gets the HTTP protocol version.
Returns
string The HTTP protocol version
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setStatusCode( integer $code, mixed $text = null )
Sets the response status code.
Sets the response status code.
Parameters
- $code
integer $code HTTP status code
- $text
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.
Returns
Throws
Api
|
public
integer
|
#
getStatusCode( )
Retrieves the status code for the current web response.
Retrieves the status code for the current web response.
Returns
integer Status code
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setCharset( string $charset )
Sets the response charset.
Sets the response charset.
Parameters
- $charset
string $charset Character set
Returns
Api
|
public
string
|
#
getCharset( )
Retrieves the response charset.
Retrieves the response charset.
Returns
string Character set
Api
|
public
Boolean
|
#
isCacheable( )
Returns true if the response is worth caching under any circumstance.
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
Api
|
public
Boolean
|
#
isFresh( )
Returns true if the response is "fresh".
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
Api
|
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.
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
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setPrivate( )
Marks the response as "private".
Marks the response as "private".
It makes the response ineligible for serving other clients.
Returns
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setPublic( )
Marks the response as "public".
Marks the response as "public".
It makes the response eligible for serving other clients.
Returns
Api
|
public
Boolean
|
#
mustRevalidate( )
Returns true if the response must be revalidated by caches.
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
Api
|
public
DateTime
|
#
getDate( )
Returns the Date header as a DateTime instance.
Returns the Date header as a DateTime instance.
Returns
Throws
Api
|
public
Symfony\Component\HttpFoundation\Response
|
|
public
integer
|
#
getAge( )
Returns the age of the response.
Returns the age of the response.
Returns
integer The age of the response in seconds
|
public
Symfony\Component\HttpFoundation\Response
|
#
expire( )
Marks the response stale by setting the Age header to be equal to the maximum
age of the response.
Marks the response stale by setting the Age header to be equal to the maximum
age of the response.
Returns
Api
|
public
DateTime |null
|
#
getExpires( )
Returns the value of the Expires header as a DateTime instance.
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
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setExpires( DateTime $date = null )
Sets the Expires HTTP header with a DateTime instance.
Sets the Expires HTTP header with a DateTime instance.
Passing null as value will remove the header.
Parameters
- $date
DateTime |null
$date A \DateTime instance or null to remove the header
Returns
Api
|
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.
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
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setMaxAge( integer $value )
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.
This methods sets the Cache-Control max-age directive.
Parameters
- $value
integer $value Number of seconds
Returns
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setSharedMaxAge( integer $value )
Sets the number of seconds after which the response should no longer be
considered fresh by shared caches.
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
- $value
integer $value Number of seconds
Returns
Api
|
public
integer|null
|
#
getTtl( )
Returns the response's time-to-live in seconds.
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
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setTtl( integer $seconds )
Sets the response's time-to-live for shared caches.
Sets the response's time-to-live for shared caches.
This method adjusts the Cache-Control/s-maxage directive.
Parameters
- $seconds
integer $seconds Number of seconds
Returns
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setClientTtl( integer $seconds )
Sets the response's time-to-live for private/client caches.
Sets the response's time-to-live for private/client caches.
This method adjusts the Cache-Control/max-age directive.
Parameters
- $seconds
integer $seconds Number of seconds
Returns
Api
|
public
DateTime |null
|
#
getLastModified( )
Returns the Last-Modified HTTP header as a DateTime instance.
Returns the Last-Modified HTTP header as a DateTime instance.
Returns
DateTime |null
A DateTime instance or null if the header does not exist
Throws
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setLastModified( DateTime $date = null )
Sets the Last-Modified HTTP header with a DateTime instance.
Sets the Last-Modified HTTP header with a DateTime instance.
Passing null as value will remove the header.
Parameters
- $date
DateTime |null
$date A \DateTime instance or null to remove the header
Returns
Api
|
public
string|null
|
#
getEtag( )
Returns the literal value of the ETag HTTP header.
Returns the literal value of the ETag HTTP header.
Returns
string|null The ETag HTTP header or null if it does not exist
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setEtag( string|null $etag = null, Boolean $weak = false )
Sets the ETag value.
Parameters
- $etag
string|null $etag The ETag unique identifier or null to remove the header
- $weak
Boolean $weak Whether you want a weak ETag or not
Returns
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setCache( array $options )
Sets the response's cache headers (validation and/or expiration).
Sets the response's cache headers (validation and/or expiration).
Available options are: etag, last_modified, max_age, s_maxage, private, and
public.
Parameters
- $options
array $options An array of cache options
Returns
Throws
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setNotModified( )
Modifies the response so that it conforms to the rules defined for a 304
status code.
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
See
Api
|
public
Boolean
|
#
hasVary( )
Returns true if the response includes a Vary header.
Returns true if the response includes a Vary header.
Returns
Boolean true if the response includes a Vary header, false otherwise
Api
|
public
array
|
#
getVary( )
Returns an array of header names given in the Vary header.
Returns an array of header names given in the Vary header.
Returns
array An array of Vary names
Api
|
public
Symfony\Component\HttpFoundation\Response
|
#
setVary( string|array $headers, Boolean $replace = true )
Sets the Vary header.
Parameters
- $headers
string|array $headers
- $replace
Boolean $replace Whether to replace the actual value of not (true by default)
Returns
Api
|
public
Boolean
|
#
isNotModified( Symfony\Component\HttpFoundation\Request $request )
Determines if the Response validators (ETag, Last-Modified) match a
conditional value specified in the 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
Returns
Boolean true if the Response validators match the Request, false otherwise
Api
|
public
Boolean
|
#
isInvalid( )
Is response invalid?
Returns
Boolean
Api
|
public
Boolean
|
|
public
Boolean
|
|
public
Boolean
|
#
isRedirection( )
Is the response a redirect?
Is the response a redirect?
Returns
Boolean
Api
|
public
Boolean
|
|
public
Boolean
|
#
isServerError( )
Was there a server side error?
Was there a server side error?
Returns
Boolean
Api
|
public
Boolean
|
#
isOk( )
Is the response OK?
Returns
Boolean
Api
|
public
Boolean
|
#
isForbidden( )
Is the response forbidden?
Is the response forbidden?
Returns
Boolean
Api
|
public
Boolean
|
#
isNotFound( )
Is the response a not found error?
Is the response a not found error?
Returns
Boolean
Api
|
public
Boolean
|
#
isRedirect( string $location = null )
Is the response a redirect of some form?
Is the response a redirect of some form?
Parameters
- $location
string $location
Returns
Boolean
Api
|
public
Boolean
|
#
isEmpty( )
Is the response empty?
Returns
Boolean
Api
|
Properties summary
protected
string
|
$content
|
|
|
protected
string
|
$version
|
|
|
protected
integer
|
$statusCode
|
|
|
protected
string
|
$statusText
|
|
|
protected
string
|
$charset
|
|
|
public static
array
|
$statusTexts
|
array(
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
208 => 'Already Reported',
226 => 'IM Used',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
306 => 'Reserved',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I\'m a teapot',
422 => 'Unprocessable Entity',
423 => 'Locked',
424 => 'Failed Dependency',
425 => 'Reserved for WebDAV advanced collections expired proposal',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates (Experimental)',
507 => 'Insufficient Storage',
508 => 'Loop Detected',
510 => 'Not Extended',
511 => 'Network Authentication Required',
) |
#
Status codes translation table.
|