ICanBoogie
  • Documentation
  • API Reference
  • HTTP v2.5.0
Namespaces
  • ICanBoogie
    • Exception
    • HTTP
      • Headers
      • Request
      • RequestDispatcher
Classes
  • CallableDispatcher
  • File
  • FileInfo
  • FileList
  • FileResponse
  • Headers
  • RedirectResponse
  • Request
  • RequestDispatcher
  • RequestRange
  • Response
  • Status
  • WeightedDispatcher
Interfaces
  • Dispatcher
  • Exception
  • SecurityError
Exceptions
  • AuthenticationRequired
  • ClientError
  • DispatcherNotDefined
  • ForceRedirect
  • MethodNotSupported
  • NotFound
  • PermissionRequired
  • ServerError
  • ServiceUnavailable
  • StatusCodeNotValid

Class Response

A response to a HTTP request.

ICanBoogie\HTTP\Response uses ICanBoogie\Accessor\AccessorTrait (not available)

Direct known subclasses

ICanBoogie\HTTP\FileResponse, ICanBoogie\HTTP\RedirectResponse

Namespace: ICanBoogie\HTTP
See: http://tools.ietf.org/html/rfc2616
Located at Response.php

Methods summary

public __construct( mixed $body = null, integer|ICanBoogie\HTTP\Status $status = Status::OK, ICanBoogie\HTTP\Headers|array $headers = [] )

Initializes the $body, $header, $date and $status properties.

Initializes the $body, $header, $date and $status properties.

Parameters

$body
The body of the response.
$status
The status code of the response.
$headers
The initial header fields of the response.
public __clone( void )

Clones the ICanBoogie\HTTP\Response::$headers and $status properties.

Clones the ICanBoogie\HTTP\Response::$headers and $status properties.

public __toString( void ) : string

Renders the response as an HTTP string.

Renders the response as an HTTP string.

Returns

string
public __invoke( void )

Issues the HTTP response.

Issues the HTTP response.

ICanBoogie\HTTP\Response::finalize() is invoked to finalize the headers (a cloned actually) and the body. ICanBoogie\HTTP\Response::send_headers() is invoked to send the headers and ICanBoogie\HTTP\Response::send_body() is invoked to send the body, if the body is not null.

The body is not send in the following instances:

  • The finalized body is null.
  • The status is not ok.
protected finalize( ICanBoogie\HTTP\Headers & $headers, mixed & $body )

Finalize the body.

Finalize the body.

Subclasses might want to override this method if they wish to alter the header or the body before the response is sent or transformed into a string.

Parameters

$headers
Reference to the final header.
$body
Reference to the final body.
protected send_headers( ICanBoogie\HTTP\Headers $headers )
protected send_body( mixed $body )

Sends response body.

Sends response body.

Parameters

$body
protected set_status( integer|ICanBoogie\HTTP\Status $status )

Sets response status code and optionally status message.

Sets response status code and optionally status message.

Parameters

$status
HTTP status code or HTTP status code and HTTP status message.
protected get_status( void ) : ICanBoogie\HTTP\Status

Returns the response status.

Returns the response status.

Returns

ICanBoogie\HTTP\Status
protected set_body( string|Closure|null $body )

Sets the response 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.

Parameters

$body

Throws

UnexpectedValueException
when the body cannot be converted to a string.
protected assert_body_is_valid( $body )

Asserts that the a body is valid.

Asserts that the a body is valid.

Parameters

$body

Throws

UnexpectedValueException
if the specified body doesn't meet the requirements.
protected get_body( void ) : string

Returns the response body.

Returns the response body.

Returns

string
protected set_location( string|null $url )

Sets the value of the Location header field.

Sets the value of the Location header field.

Parameters

$url
protected get_location( void ) : string

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
protected get_content_type( void ) : ICanBoogie\HTTP\Headers\ContentType

Returns the value of the Content-Type header field.

Returns the value of the Content-Type header field.

Returns

ICanBoogie\HTTP\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

$length
protected get_content_length( void ) : integer

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

$time
protected get_date( void ) : ICanBoogie\HTTP\Headers\Date

Returns the value of the Date header field.

Returns the value of the Date header field.

Returns

ICanBoogie\HTTP\Headers\Date
protected set_age( integer $age )

Sets the value of the Age header field.

Sets the value of the Age header field.

Parameters

$age
protected get_age( void ) : integer

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

$time
protected get_last_modified( void ) : ICanBoogie\HTTP\Headers\Date

Returns the value of the Last-Modified header field.

Returns the value of the Last-Modified header field.

Returns

ICanBoogie\HTTP\Headers\Date
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

$time
protected get_expires( void ) : ICanBoogie\HTTP\Headers\Date

Returns the value of the Expires header field.

Returns the value of the Expires header field.

Returns

ICanBoogie\HTTP\Headers\Date
protected set_etag( string $value )

Sets the value of the ETag header field.

Sets the value of the ETag header field.

Parameters

$value
protected get_etag( void ) : string

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
protected get_cache_control( void ) : ICanBoogie\HTTP\Headers\CacheControl

Returns the Cache-Control header field.

Returns the Cache-Control header field.

Returns

ICanBoogie\HTTP\Headers\CacheControl
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
The number of seconds.
protected get_ttl( void ) : integer|null

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 re-validating with the origin.

Returns

integer|null

The number of seconds to live, or null is no freshness information is present.

protected get_is_validateable( void ) : boolean

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 get_is_cacheable( void ) : boolean

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 not cacheable.

Responses with neither a freshness lifetime (Expires, max-age) nor cache validator (Last-Modified, ETag) are considered not cacheable.

Returns

boolean
protected get_is_fresh( void ) : boolean

Checks if the response is fresh.

Checks if the response is fresh.

Returns

boolean

Properties summary

public $headers : ICanBoogie\HTTP\Headers

Response headers.

Response headers.


		
public $version : string

The HTTP protocol version (1.0 or 1.1), defaults to '1.0'

The HTTP protocol version (1.0 or 1.1), defaults to '1.0'

'1.0'

Magic properties

public $status : ICanBoogie\HTTP\Status
public $body : mixed

The body of the response.

public $ttl : integer

Adjusts the s-maxage part of the Cache-Control header field definition according to the Age header field definition.

public $age : integer

Shortcut to the Age header field definition.

public $cache_control : ICanBoogie\HTTP\Headers\CacheControl

Shortcut to the Cache-Control header field definition.

public $content_length : integer

Shortcut to the Content-Length header field definition.

public $content_type : ICanBoogie\HTTP\Headers\ContentType

Shortcut to the Content-Type header field definition.

public $date : ICanBoogie\HTTP\Headers\Date

Shortcut to the Date header field definition.

public $etag : string

Shortcut to the ETag header field definition.

public $expires : ICanBoogie\HTTP\Headers\Date

Shortcut to the Expires header field definition.

public $last_modified : ICanBoogie\HTTP\Headers\Date

Shortcut to the Last-Modified header field definition.

public $location : string

Shortcut to the Location header field definition.

public read-only $is_cacheable : boolean

ICanBoogie\HTTP\Response::get_is_cacheable()

public read-only $is_fresh : boolean

ICanBoogie\HTTP\Response::get_is_fresh()

public read-only $is_private : boolean

get_is_private()

public read-only $is_validateable : boolean

ICanBoogie\HTTP\Response::get_is_validateable()

HTTP v2.5.0 – Check on GitHub – API documentation generated by ApiGen