class Response implements IResponse

HttpResponse class.

Traits

Strict class for better experience.

Properties

string $cookieDomain
string $cookiePath
bool $cookieSecure
bool $cookieHttpOnly
bool $warnOnBuffer

Methods

__construct()

No description

setCode(int $code, string $reason = null)

Sets HTTP response code.

int
getCode()

Returns HTTP response code.

setHeader(string $name, string $value)

Sends a HTTP header and replaces a previous one.

addHeader(string $name, string $value)

Adds HTTP header.

self
deleteHeader(string $name)

No description

setContentType(string $type, string $charset = null)

Sends a Content-type HTTP header.

void
redirect(string $url, int $code = self::S302_FOUND)

Redirects to a new URL. Note: call exit() after it.

setExpiration(string|null $time)

Sets the time (like '20 minutes') before a page cached on a browser expires, null means "must-revalidate".

bool
isSent()

Checks if headers have been sent.

string|null
getHeader(string $header)

Returns value of an HTTP header.

array
getHeaders()

Returns a associative array of headers to sent.

__destruct()

No description

setCookie(string $name, string $value, $time, string $path = null, string $domain = null, bool $secure = null, bool $httpOnly = null, string $sameSite = null)

Sends a cookie.

deleteCookie(string $name, string $path = null, string $domain = null, bool $secure = null)

Deletes a cookie.

Details

at line 47
__construct()

at line 61
IResponse setCode(int $code, string $reason = null)

Sets HTTP response code.

Parameters

int $code
string $reason

Return Value

IResponse

Exceptions

InvalidArgumentException if code is invalid
InvalidStateException if HTTP headers have been sent

at line 78
int getCode()

Returns HTTP response code.

Return Value

int

at line 89
IResponse setHeader(string $name, string $value)

Sends a HTTP header and replaces a previous one.

Parameters

string $name
string $value

Return Value

IResponse

Exceptions

InvalidStateException if HTTP headers have been sent

at line 108
IResponse addHeader(string $name, string $value)

Adds HTTP header.

Parameters

string $name
string $value

Return Value

IResponse

Exceptions

InvalidStateException if HTTP headers have been sent

at line 120
self deleteHeader(string $name)

Parameters

string $name

Return Value

self

Exceptions

InvalidStateException if HTTP headers have been sent

at line 133
IResponse setContentType(string $type, string $charset = null)

Sends a Content-type HTTP header.

Parameters

string $type
string $charset

Return Value

IResponse

Exceptions

InvalidStateException if HTTP headers have been sent

at line 144
void redirect(string $url, int $code = self::S302_FOUND)

Redirects to a new URL. Note: call exit() after it.

Parameters

string $url
int $code

Return Value

void

Exceptions

InvalidStateException if HTTP headers have been sent

at line 160
IResponse setExpiration(string|null $time)

Sets the time (like '20 minutes') before a page cached on a browser expires, null means "must-revalidate".

Parameters

string|null $time

Return Value

IResponse

Exceptions

InvalidStateException if HTTP headers have been sent

at line 179
bool isSent()

Checks if headers have been sent.

Return Value

bool

at line 188
string|null getHeader(string $header)

Returns value of an HTTP header.

Parameters

string $header

Return Value

string|null

at line 207
array getHeaders()

Returns a associative array of headers to sent.

Return Value

array

at line 218
__destruct()

at line 238
IResponse setCookie(string $name, string $value, $time, string $path = null, string $domain = null, bool $secure = null, bool $httpOnly = null, string $sameSite = null)

Sends a cookie.

Parameters

string $name
string $value
$time
string $path
string $domain
bool $secure
bool $httpOnly
string $sameSite

Return Value

IResponse

Exceptions

InvalidStateException if HTTP headers have been sent

at line 270
deleteCookie(string $name, string $path = null, string $domain = null, bool $secure = null)

Deletes a cookie.

Parameters

string $name
string $path
string $domain
bool $secure

Exceptions

InvalidStateException if HTTP headers have been sent