public
|
#
__construct( mixed $body = null, integer $status = 200, ICanBoogie\HTTP\Headers |array $headers = array() )
Initializes the $body, $header, $date and $status properties.
Initializes the $body, $header, $date and $status properties.
Parameters
- $body
mixed $body The body of the response.
- $status
integer $status The status code of the response.
- $headers
ICanBoogie\HTTP\Headers |array
$headers The initial header fields of the response.
|
public
|
#
__set( string $property, mixed $value )
Handles read-only properties.
Handles read-only properties.
Parameters
- $property
string $property
- $value
mixed $value
Throws
ICanBoogie\PropertyNotWritable
in attempt to write one of the following properties: $is_valid, $is_informational, $is_successful, $is_redirect), {@link
$is_client_error, $is_server_error, $is_ok, $is_forbidden, $is_not_found, $is_empty, $is_validateable, $is_cacheable, $is_fresh
Overrides
|
public
|
#
__clone( )
Clones the {@link $headers] property.
Clones the {@link $headers] property.
|
public
string
|
#
__toString( )
Renders the response as an HTTP string.
Renders the response as an HTTP string.
Returns
string
|
public
|
#
__invoke( )
Issues the HTTP response.
Issues the HTTP response.
The header is modified according to the ICanBoogie\HTTP\Response::$version , status and
ICanBoogie\HTTP\Response::$status_message properties.
The usual behaviour of the response is to echo its body and then terminate
the script. But if its body is null the following happens :
- If the $location property is defined the script is terminated.
- If the $is_ok property is falsy the method
returns.
Note: If the body is a string, or an object implementing the
__toString() method, the Content-Length header is
automatically defined to the lenght of the body string.
Note: If the body is an instance of Closure it MUST echo the
response's body.
|
protected
|
#
set_status( integer|array $status )
Sets response status code and optionally status message.
Sets response status code and optionally status message.
This method is the setter for the $status property.
Parameters
- $status
integer|array $status HTTP status code or HTTP status code and HTTP status message.
Throws
|
protected
integer
|
#
get_status( )
Returns the response status code.
Returns the response status code.
This method is the getter for the $status property.
Returns
integer
|
protected
|
#
set_body( string|Closure |null $body )
Sets the response body.
The body can be any data type that can be converted into a string this
includes numeric and objects implementing the ICanBoogie\HTTP\Response::__toString() method.
Note: This method is the setter for the $body property.
Parameters
Throws
|
protected
string
|
#
get_body( )
Returns the response body.
Returns the response body.
Note: This method is the getter for the $body property.
Returns
string
|
protected
|
#
echo_body( mixed $body )
Echo the body.
Parameters
|
protected
string
|
|
protected
|
#
set_location( string|null $url )
Sets the value of the Location header field.
Sets the value of the Location header field.
Parameters
|
protected
string
|
#
get_location( )
Returns the value of the Location header field.
Returns the value of the Location header field.
Returns
string
|
protected
|
#
set_content_type( string $content_type )
Sets the value of the Content-Type header field.
Sets the value of the Content-Type header field.
Parameters
- $content_type
string $content_type
|
protected
Headers\ContentType
|
#
get_content_type( )
Returns the value of the Content-Type header field.
Returns the value of the Content-Type header field.
Returns
Headers\ContentType
|
protected
|
#
set_content_length( integer $length )
Sets the value of the Content-Length header field.
Sets the value of the Content-Length header field.
Parameters
|
protected
integer
|
#
get_content_length( )
Returns the value of the Content-Length header field.
Returns the value of the Content-Length header field.
Returns
integer
|
protected
|
#
set_date( mixed $time )
Sets the value of the Date header field.
Sets the value of the Date header field.
Parameters
|
protected
Headers\DateHeader
|
#
get_date( )
Returns the value of the Date header field.
Returns the value of the Date header field.
Returns
Headers\DateHeader
|
protected
|
#
set_age( integer $age )
Sets the value of the Age header field.
Sets the value of the Age header field.
Parameters
|
protected
integer
|
#
get_age( )
Returns the age of the response.
Returns the age of the response.
Returns
integer
|
protected
|
#
set_last_modified( mixed $time )
Sets the value of the Last-Modified header field.
Sets the value of the Last-Modified header field.
Parameters
|
protected
Headers\DateHeader
|
#
get_last_modified( )
Returns the value of the Last-Modified header field.
Returns the value of the Last-Modified header field.
Returns
Headers\DateHeader
|
protected
|
#
set_expires( mixed $time )
Sets the value of the Expires header field.
Sets the value of the Expires header field.
The method also calls the session_cache_expire() function.
Parameters
|
protected
Headers\DateHeader
|
#
get_expires( )
Returns the value of the Expires header field.
Returns the value of the Expires header field.
Returns
Headers\DateHeader
|
protected
|
#
set_etag( string $value )
Sets the value of the Etag header field.
Sets the value of the Etag header field.
Parameters
|
protected
string
|
#
get_etag( )
Returns the value of the Etag header field.
Returns the value of the Etag header field.
Returns
string
|
protected
|
#
set_cache_control( string $cache_directives )
Sets the directives of the Cache-Control header field.
Sets the directives of the Cache-Control header field.
Parameters
- $cache_directives
string $cache_directives
|
protected
ICanBoogie\HTTP\CacheControlHeader
|
#
get_cache_control( )
Returns the Cache-Control header field.
Returns the Cache-Control header field.
Returns
|
protected
|
#
set_ttl( 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 The number of seconds.
|
protected
integer|null
|
#
get_ttl( )
Returns the response's time-to-live in seconds.
Returns the response's time-to-live in seconds.
When the responses TTL is <= 0, the response may not be served from cache
without first revalidating with the origin.
Returns
integer|null The number of seconds to live, or null is no freshness information
is present.
|
protected
|
#
set_is_private( boolean $value )
Set the cacheable property of the Cache-Control
header field to private .
Set the cacheable property of the Cache-Control
header field to private .
Parameters
|
protected
boolean
|
#
get_is_private( )
Checks that the cacheable property of the
Cache-Control header field is private .
Checks that the cacheable property of the
Cache-Control header field is private .
Returns
boolean
|
protected
boolean
|
#
get_is_valid( )
Checks if the response is valid.
Checks if the response is valid.
A response is considered valid when its status is between 100 and 600, 100
included.
Note: This method is the getter for the is_valid magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_informational( )
Checks if the response is informational.
Checks if the response is informational.
A response is considered informational when its status is between 100 and
200, 100 included.
Note: This method is the getter for the is_informational magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_successful( )
Checks if the response is successful.
Checks if the response is successful.
A response is considered successful when its status is between 200 and 300,
200 included.
Note: This method is the getter for the is_successful magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_redirect( )
Checks if the response is a redirection.
Checks if the response is a redirection.
A response is considered to be a redirection when its status is between 300
and 400, 300 included.
Note: This method is the getter for the is_redirect magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_client_error( )
Checks if the response is a client error.
Checks if the response is a client error.
A response is considered a client error when its status is between 400 and
500, 400 included.
Note: This method is the getter for the is_client_error magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_server_error( )
Checks if the response is a server error.
Checks if the response is a server error.
A response is considered a server error when its status is between 500 and
600, 500 included.
Note: This method is the getter for the is_server_error magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_ok( )
Checks if the response is ok.
Checks if the response is ok.
A response is considered ok when its status is 200.
Note: This method is the getter for the is_ok magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_forbidden( )
Checks if the response is forbidden.
Checks if the response is forbidden.
A response is forbidden ok when its status is 403.
Note: This method is the getter for the is_forbidden magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_not_found( )
Checks if the response is not found.
Checks if the response is not found.
A response is considered not found when its status is 404.
Note: This method is the getter for the is_not_found magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_empty( )
Checks if the response is empty.
Checks if the response is empty.
A response is considered empty when its status is 201, 204 or 304.
Note: This method is the getter for the is_empty magic
property.
Returns
boolean
|
protected
boolean
|
#
get_is_validateable( )
Checks that the response includes header fields that can be used to validate
the response with the origin server using a conditional GET request.
Checks that the response includes header fields that can be used to validate
the response with the origin server using a conditional GET request.
Returns
boolean
|
protected
boolean
|
#
get_is_cacheable( )
Checks that the response is worth caching under any circumstance.
Checks that 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
|
protected
boolean
|
#
get_is_fresh( )
Checks if the response is fresh.
Checks if the response is fresh.
Returns
boolean
|