final class Response implements IResponse

HttpResponse class.

Properties

string $cookieDomain
string $cookiePath
bool $cookieSecure
deprecated $cookieHttpOnly
bool $warnOnBuffer
array read-only $headers

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 an HTTP header and overwrites previously sent header of the same name.

addHeader(string $name, string $value)

Sends an HTTP header and doesn't overwrite previously sent header of the same name.

self
deleteHeader(string $name)

Deletes a previously sent HTTP header.

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

Sends a Content-type HTTP header.

sendAsFile(string $fileName)

Response should be downloaded with 'Save as' dialog.

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

Redirects to another URL. Don't forget to quit the script then.

setExpiration(string|null $time)

Sets the expiration of the HTTP document using the Cache-Control and Expires headers.

bool
isSent()

Returns whether headers have already been sent from the server to the browser, so it is no longer possible to send headers or change the response code.

string|null
getHeader(string $header)

Returns the sent HTTP header, or null if it does not exist. The parameter is case-insensitive.

array
getHeaders()

Returns all sent HTTP headers as associative array.

__destruct()

No description

setCookie(string $name, string $value, string|int|DateTimeInterface $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()

No description

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

Sets HTTP response code.

Parameters

int $code
string $reason

Return Value

IResponse

Exceptions

InvalidArgumentException
InvalidStateException

at line 78
int getCode()

Returns HTTP response code.

Return Value

int

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

Sends an HTTP header and overwrites previously sent header of the same name.

Parameters

string $name
string $value

Return Value

IResponse

Exceptions

InvalidStateException

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

Sends an HTTP header and doesn't overwrite previously sent header of the same name.

Parameters

string $name
string $value

Return Value

IResponse

Exceptions

InvalidStateException

at line 121
self deleteHeader(string $name)

Deletes a previously sent HTTP header.

Parameters

string $name

Return Value

self

Exceptions

InvalidStateException

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

Sends a Content-type HTTP header.

Parameters

string $type
string $charset

Return Value

IResponse

Exceptions

InvalidStateException

at line 146
Response sendAsFile(string $fileName)

Response should be downloaded with 'Save as' dialog.

Parameters

string $fileName

Return Value

Response

Exceptions

InvalidStateException

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

Redirects to another URL. Don't forget to quit the script then.

Parameters

string $url
int $code

Return Value

void

Exceptions

InvalidStateException

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

Sets the expiration of the HTTP document using the Cache-Control and Expires headers.

The parameter is either a time interval (as text) or null, which disables caching.

Parameters

string|null $time

Return Value

IResponse

Exceptions

InvalidStateException

at line 198
bool isSent()

Returns whether headers have already been sent from the server to the browser, so it is no longer possible to send headers or change the response code.

Return Value

bool

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

Returns the sent HTTP header, or null if it does not exist. The parameter is case-insensitive.

Parameters

string $header

Return Value

string|null

at line 226
array getHeaders()

Returns all sent HTTP headers as associative array.

Return Value

array

at line 237
__destruct()

No description

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

Sends a cookie.

Parameters

string $name
string $value
string|int|DateTimeInterface $time

expiration time, value null means "until the browser session ends"

string $path
string $domain
bool $secure
bool $httpOnly
string $sameSite

Return Value

IResponse

Exceptions

InvalidStateException

at line 297
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

Traits

SmartObject