Response
+ Inheritance diagram for Response:

Description

The response.

Protected Properties

int $code = 404
 
array $headers
 Associative values and/or enumerated literal headers. More...
 
string $id
 X-Response-Id, also used in logging errors. More...
 
Request $request
 
Site $site
 
int $timestamp = 0
 Last modification time. More...
 

Public Methods

 __construct (Site $site)
 
void error_exit (Throwable $error=null)
 Renders an error and exits. More...
 
void file_exit (string $path, bool $download=false)
 Outputs a file (or requested range) and exits. More...
 
int getCode ()
 
string getId ()
 
int getTimestamp ()
 
bool isEmpty ()
 Whether the response will only consist of headers. More...
 
bool isModified ()
 Whether the response body would be considered fresh. More...
 
void mixed_exit ($content)
 Renders mixed content and exits. More...
 
bool offsetExists ($key)
 
null string offsetGet ($key)
 
 offsetSet ($key, $value)
 
 offsetUnset ($key)
 
void redirect_exit (string $location, int $code=302)
 Issues a redirect and exits. More...
 
$this setCacheTtl ($ttl)
 Specifies how long the response can be cached by the client. More...
 
$this setCode (int $code)
 
$this setTimestamp (int $timestamp)
 Sets or unsets the timestamp and Last-Modified header. More...
 
$this touch (int $timestamp)
 Updates the modification time if the given one is greater. More...
 
void view_exit (View $view)
 Renders a view and exits. More...
 

Properties

◆ $headers

array $headers
protected
Initial value:
= [
'Accept-Ranges' => 'none',
'Cache-Control' => 'no-store'
]

Associative values and/or enumerated literal headers.

◆ $id

string $id
protected

X-Response-Id, also used in logging errors.

◆ $timestamp

int $timestamp = 0
protected

Last modification time.

Ignored when zero.

Constructor

◆ __construct()

__construct ( Site  $site)
Parameters
Site$site

Methods

◆ error_exit()

void error_exit ( Throwable  $error = null)

Renders an error and exits.

Parameters
null | Throwable$errorDefaults to an HttpError with the current response code.

◆ file_exit()

void file_exit ( string  $path,
bool  $download = false 
)

Outputs a file (or requested range) and exits.

Parameters
string$path
bool$download

◆ getCode()

int getCode ( )
final
Returns
int

◆ getId()

string getId ( )
final
Returns
string

◆ getTimestamp()

int getTimestamp ( )
Returns
int

◆ isEmpty()

bool isEmpty ( )

Whether the response will only consist of headers.

Returns
bool

◆ isModified()

bool isModified ( )

Whether the response body would be considered fresh.

Returns
bool

◆ mixed_exit()

void mixed_exit (   $content)

Renders mixed content and exits.

Parameters
mixed$content

◆ offsetExists()

bool offsetExists (   $key)
Parameters
mixed$key
Returns
bool

◆ offsetGet()

null string offsetGet (   $key)
Parameters
mixed$key
Returns
null|string

◆ offsetSet()

offsetSet (   $key,
  $value 
)
Parameters
mixed$key
string$value

◆ offsetUnset()

offsetUnset (   $key)
Parameters
mixed$key

◆ redirect_exit()

void redirect_exit ( string  $location,
int  $code = 302 
)

Issues a redirect and exits.

Parameters
string$location
int$code

◆ setCacheTtl()

$this setCacheTtl (   $ttl)

Specifies how long the response can be cached by the client.

Parameters
int | DateTimeInterface$ttlZero or negative time means "don't cache"
Returns
$this

◆ setCode()

$this setCode ( int  $code)
Parameters
int$code
Returns
$this

◆ setTimestamp()

$this setTimestamp ( int  $timestamp)

Sets or unsets the timestamp and Last-Modified header.

Parameters
int$timestamp
Returns
$this

◆ touch()

$this touch ( int  $timestamp)

Updates the modification time if the given one is greater.

Parameters
int$timestamp
Returns
$this

◆ view_exit()

void view_exit ( View  $view)

Renders a view and exits.

If the request is HEAD this skips rendering content and only outputs headers.

Parameters
View$view