Documentation

Response
in package
Uses TEventDispatcher

Response Class

Represents a class responsible for output.

Table of Contents

Properties

$codes  : array<string|int, mixed>
HTTP response status codes and their descriptions.
$instance  : Response|null
Singleton instance.

Methods

Cache()  : Response
Set caching options for the HTTP response.
CacheControl()  : Response
Set the Cache-Control header for the HTTP response.
Close()  : void
Echo result and stop
ContentDisposition()  : Response
Set the Content-Disposition header for the HTTP response.
ContentLength()  : Response
Set the Content-Length header for the HTTP response.
ContentTransferEncoding()  : Response
Set the Content-Transfer-Encoding header for the HTTP response.
ContentType()  : Response
Set the Content-Type header for the HTTP response.
Cookie()  : Response
Set a cookie in the HTTP response.
Create()  : Response
Static constructor to create a singleton instance.
DispatchEvent()  : object|null
Dispatches an event.
DownloadFile()  : void
Complex method to return a file
Error404()  : void
Returns error and stops
ExpiresAfter()  : Response
Set the expiration time for the HTTP response.
ExpiresAt()  : Response
Set the expiration time for the HTTP response.
FileTransfer()  : Response
Add the Content-Description header to the HTTP response.
HandleEvent()  : self
Adds an event handler.
NoCache()  : Response
Disable caching for the HTTP response.
Origin()  : void
Writes origin to response
P3P()  : Response
Set the P3P header for the HTTP response.
Pragma()  : Response
Set the Pragma header for the HTTP response.
Redirect()  : Response
Redirect the client to another URL.
Refresh()  : Response
Refresh the current page.
RemoveHandler()  : self
Removes an event handler.
SaveUTMCookies()  : Response
Saves UTM cookie values to cookie
Write()  : void
Echo function analogue
__construct()  : mixed
Constructor (private to enforce singleton pattern).
_addHeader()  : void
Add a header to the HTTP response.
_addHeaders()  : void
Add multiple headers to the HTTP response.

Properties

$codes

HTTP response status codes and their descriptions.

public static array<string|int, mixed> $codes = [ 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', // WebDAV; RFC 2518 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', // since HTTP/1.1 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', // WebDAV; RFC 4918 208 => 'Already Reported', // WebDAV; RFC 5842 226 => 'IM Used', // RFC 3229 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', // since HTTP/1.1 304 => 'Not Modified', 305 => 'Use Proxy', // since HTTP/1.1 306 => 'Switch Proxy', 307 => 'Temporary Redirect', // since HTTP/1.1 308 => 'Permanent Redirect', // approved as experimental RFC 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', // RFC 2324 419 => 'Authentication Timeout', // not in RFC 2616 420 => 'Enhance Your Calm', // Twitter 422 => 'Unprocessable Entity', // WebDAV; RFC 4918 423 => 'Locked', // WebDAV; RFC 4918 424 => 'Failed Dependency', // WebDAV; RFC 4918 425 => 'Unordered Collection', // Internet draft 426 => 'Upgrade Required', // RFC 2817 428 => 'Precondition Required', // RFC 6585 429 => 'Too Many Requests', // RFC 6585 431 => 'Request Header Fields Too Large', // RFC 6585 444 => 'No Response', // Nginx 449 => 'Retry With', // Microsoft 450 => 'Blocked by Windows Parental Controls', // Microsoft 451 => 'Redirect', // Microsoft 494 => 'Request Header Too Large', // Nginx 495 => 'Cert Error', // Nginx 496 => 'No Cert', // Nginx 497 => 'HTTP to HTTPS', // Nginx 499 => 'Client Closed Request', // Nginx 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates', // RFC 2295 507 => 'Insufficient Storage', // WebDAV; RFC 4918 508 => 'Loop Detected', // WebDAV; RFC 5842 509 => 'Bandwidth Limit Exceeded', // Apache bw/limited extension 510 => 'Not Extended', // RFC 2774 511 => 'Network Authentication Required', // RFC 6585 598 => 'Network read timeout error', // Unknown 599 => 'Network connect timeout error', ]

Methods

Cache()

Set caching options for the HTTP response.

public Cache(int $seconds) : Response
Parameters
$seconds : int

The number of seconds to cache the response.

Return values
Response

The Response instance.

CacheControl()

Set the Cache-Control header for the HTTP response.

public CacheControl(string $type) : Response
Parameters
$type : string

The value of the Cache-Control header.

Return values
Response

The Response instance.

Close()

Echo result and stop

public Close(int $status[, string $content = '' ][, string $type = 'text/html' ][, string $encoding = 'utf-8' ][, array<string|int, mixed>|null $headers = [] ][, array<string|int, mixed>|null $cookies = [] ]) : void
Parameters
$status : int

status of response

$content : string = ''

content of response

$type : string = 'text/html'
$encoding : string = 'utf-8'
$headers : array<string|int, mixed>|null = []
$cookies : array<string|int, mixed>|null = []

ContentDisposition()

Set the Content-Disposition header for the HTTP response.

public ContentDisposition(string $type, string $name) : Response
Parameters
$type : string

The type of disposition ('attachment', 'inline').

$name : string

The filename to be sent to the client.

Return values
Response

The Response instance.

ContentLength()

Set the Content-Length header for the HTTP response.

public ContentLength(int $length) : Response
Parameters
$length : int

The length of the content in bytes.

Return values
Response

The Response instance.

ContentTransferEncoding()

Set the Content-Transfer-Encoding header for the HTTP response.

public ContentTransferEncoding([string $type = 'binary' ]) : Response
Parameters
$type : string = 'binary'

The transfer encoding type ('binary', 'base64', etc.).

Return values
Response

The Response instance.

ContentType()

Set the Content-Type header for the HTTP response.

public ContentType(string $type[, string|null $encoding = null ]) : Response
Parameters
$type : string

The MIME type of the content.

$encoding : string|null = null

The character encoding of the content.

Return values
Response

The Response instance.

Set a cookie in the HTTP response.

public Cookie(string $name, string $value[, int|null $expires = 0 ][, string|null $path = '' ][, string|null $domain = '' ][, bool|null $secure = false ][, bool|null $httponly = false ]) : Response
Parameters
$name : string

The name of the cookie.

$value : string

The value of the cookie.

$expires : int|null = 0

The expiration time of the cookie in seconds.

$path : string|null = ''

The path on the server in which the cookie will be available.

$domain : string|null = ''

The domain that the cookie is available to.

$secure : bool|null = false

Indicates if the cookie should only be transmitted over a secure HTTPS connection.

$httponly : bool|null = false

Indicates if the cookie should only be accessible through HTTP protocol.

Return values
Response

The Response instance.

Create()

Static constructor to create a singleton instance.

public static Create() : Response
Return values
Response

The singleton instance.

DispatchEvent()

Dispatches an event.

public DispatchEvent(string|Event $event[, mixed $args = null ][, bool $async = false ]) : object|null
Parameters
$event : string|Event

The event object or its name.

$args : mixed = null

Additional arguments to pass to the event handlers.

$async : bool = false

Whether to dispatch the event asynchronously.

Return values
object|null

The event object with updated arguments, or null if the event does not exist.

DownloadFile()

Complex method to return a file

public DownloadFile(string $filename, string $filecontent) : void
Parameters
$filename : string

a file name

$filecontent : string

file content

Error404()

Returns error and stops

public Error404([string $content = '' ]) : void
Parameters
$content : string = ''

ExpiresAfter()

Set the expiration time for the HTTP response.

public ExpiresAfter(int $seconds) : Response
Parameters
$seconds : int

The number of seconds until expiration.

Return values
Response

The Response instance.

ExpiresAt()

Set the expiration time for the HTTP response.

public ExpiresAt(int $date) : Response
Parameters
$date : int

The expiration date as a Unix timestamp.

Return values
Response

The Response instance.

FileTransfer()

Add the Content-Description header to the HTTP response.

public FileTransfer() : Response
Return values
Response

The Response instance.

HandleEvent()

Adds an event handler.

public HandleEvent(array<string|int, mixed>|string $ename, mixed $listener) : self
Parameters
$ename : array<string|int, mixed>|string

The event name or an array of event names.

$listener : mixed

The event handler.

Return values
self

NoCache()

Disable caching for the HTTP response.

public NoCache() : Response
Return values
Response

The Response instance.

Origin()

Writes origin to response

public Origin() : void

P3P()

Set the P3P header for the HTTP response.

public P3P() : Response
Return values
Response

The Response instance.

Pragma()

Set the Pragma header for the HTTP response.

public Pragma([string $type = 'binary' ]) : Response
Parameters
$type : string = 'binary'

Type of pragma header

Return values
Response

The Response instance.

Redirect()

Redirect the client to another URL.

public Redirect(string $url[, int $status = 301 ]) : Response
Parameters
$url : string

The URL to redirect to.

$status : int = 301

The HTTP status code for the redirect.

Return values
Response

The Response instance.

RemoveHandler()

Removes an event handler.

public RemoveHandler(string $ename, mixed $listener) : self
Parameters
$ename : string

The event name.

$listener : mixed

The event handler to remove.

Return values
self

SaveUTMCookies()

Saves UTM cookie values to cookie

public SaveUTMCookies(IteratorAggregate $utm) : Response
Parameters
$utm : IteratorAggregate
Return values
Response

Write()

Echo function analogue

public Write() : void

__construct()

Constructor (private to enforce singleton pattern).

private __construct() : mixed

_addHeader()

Add a header to the HTTP response.

private _addHeader(string $name, string $value) : void
Parameters
$name : string

The name of the header.

$value : string

The value of the header.

Tags
testFunction

testResponse_addHeader

_addHeaders()

Add multiple headers to the HTTP response.

private _addHeaders(array<string|int, mixed> $headers) : void
Parameters
$headers : array<string|int, mixed>

An associative array of headers (name => value).


        
On this page

Search results