IResponse

Interface for response.
Source
IResponse.php
Implementations
Response

Static Methods

getHttpStatusCodes

array|string|null IResponse::getHttpStatusCodes(int | string code=null)

Get a list of all HTTP status codes, or get the full status by passing only the code.

Arguments

    code=null (int | string)
    Status code as int or string or with description

Returns

array|string|null
If argument is not passed then all status codes will be returned as {code: code-and-description,} if argument is passed and identifies a valid HTTP status code then the full HTTP status line will be returned

headerSent

bool IResponse::headerSent()

Check if headers have been sent to the client.

Returns

bool
true=headers have been sent

Methods

__get

mixed __get(string key)

Get a response context var. Context vars can be accessed as properties and will be available in the response context e.g. templates, JSON, etc.

Arguments

    key (string)
    Var name

Returns

mixed
Var value

__isset

bool __isset(string key)

Check if a varable exists in the response context.

Arguments

    key (string)
    Context variable(key) name

Returns

bool
true=exists

__set

void __set(string key, mixed val)

Set a response context var. Context vars can be accessed as properties and will be available in the response context e.g. templates, JSON, etc.

Arguments

    key (string)
    Var name
    val (mixed)
    Var value

Returns

void

__unset

void __unset(string key)

Unset a response context variable.

Arguments

    key (string)
    Context variable(key) name

Returns

void

addCssFile

IResponse $obj->addCssFile([string] file)

Add a CSS file to the response context. The CSS list in the response context is available in the template or the data pack being sent to the client for on-demand CSS loading.

Arguments

    file ([string])
    CSS file URL or browser dictionary key to a CSS file URL

Returns

IResponse
For method chaining

addJsFile

IResponse $obj->addJsFile([string] file)

Add a JS file to the response context. The JS list in the response context is available in the template or the data pack being sent to the client for on-demand JS loading.

Arguments

    file ([string])
    JS file URL or browser dictionary key to a JS file URL

Returns

IResponse
For method chaining

addJsSource

IResponse $obj->addJsSource([string] sourceCode)

Add a JS source to the response context. The JS source list in the response context is available in the template or the data pack being sent to the client for execution.

Arguments

    sourceCode ([string])
    JS source code

Returns

IResponse
For method chaining

arta

array $obj->arta()

Get the Artaengine extra data which is be included to the response context. To exclude this data from the response context in a factory set "$this->__arta__ = false;".

Returns

array
{
    string title     : app-title (from app configs array or ini),
    string BASE_URL  : the BASE_URL,
    bool   DEBUG     : app DEBUG status (from app configs array or ini),
    string resources : {
        string fav : fav ico URL (from app configs array or ini),
        array  js  : [list-of-js-files-to-be-included-to-the-page],
        array  css : [list-of-css-files-to-be-included-to-the-page],
        string jsx : JavaScript source codes to be executed,
    }
}

clear

IResponse $obj->clear()

Clear all context vars.

Returns

IResponse
For method chaining

get

mixed $obj->get(string key)

Get a response context var. Context vars can be accessed as properties and will be available in the response context e.g. templates, JSON, etc.

Arguments

    key (string)
    Var name

Returns

mixed
Var value

getCssUrl

string $obj->getCssUrl(string key)

Get the URL for a CSS file by a browser dictionary key.

Arguments

    key (string)
    A browser dictionary key that is mappeed to a CSS file

Returns

string
URL

getJsUrl

string $obj->getJsUrl(string key)

Get the URL for a JS file by a browser dictionary key.

Arguments

    key (string)
    A browser dictionary key that is mappeed to a JS file

Returns

string
URL

getTemplate

string $obj->getTemplate(string template)

Render a template and return the contents.

Arguments

    template (string)
    Template filename or a template dictionary key

Returns

string
The template contents

has

bool $obj->has(string key)

Check if a variable exists in the response context.

Arguments

    key (string)
    Context variable(key) name

Returns

bool
true=exists

redirect

void $obj->redirect(string url=null)

Redirect to a URL.

Arguments

    url=null (string)
    The URL, null=redirect to base URL, if it's string is a path e.g. "/path" the redirect URL would be considered as "BASE_URL/path"

Returns

void

remove

void $obj->remove(string key)

Unset a response context variable.

Arguments

    key (string)
    Context variable(key) name

Returns

void

sendFile

void $obj->sendFile(string filePath, string asFilename=null, string fileType=null)

Send a file to be downloaded.

Arguments

    filePath (string)
    File path
    asFilename=null (string)
    Download file as this filename
    fileType=null (string)
    File type, null=it will be guessed

Returns

void

set

IResponse $obj->set(string key, mixed val)

Set a response context var. Context vars can be accessed as properties and will be available in the response context e.g. templates, JSON, etc.

Arguments

    key (string)
    Var name
    val (mixed)
    Var value

Returns

IResponse
For method chaining

setHttpStatus

IHeaders $obj->setHttpStatus(string | int code)

Set the response HTTP status code. Invalid status codes will be ignored.

Arguments

    code (string | int)
    An HTTP status code or an HTTP status code and description

Returns

IHeaders
For method chaining

setHttpVersion

IHeaders $obj->setHttpVersion(string version=1.1)

Set the HTTP version. Invalid values will be ignored.

Arguments

    version=1.1 (string)
    HTTP version

Returns

IHeaders
For method chaining

showFile

IResponse $obj->showFile(string filePath, string fileType=null)

Output file contents.

Arguments

    filePath (string)
    File path
    fileType=null (string)
    File type, null=it will be guessed

Returns

IResponse
For method chaining

write

IResponse $obj->write(string | array contents=null, string charset=utf-8)

Output text. If an array is passed the array dump will be sent.

Arguments

    contents=null (string | array)
    Data to output, null=write the response context values
    charset=utf-8 (string)
    Character-set, null=do not send any additional headers

Returns

IResponse
For method chaining

writeClose

IResponse $obj->writeClose(string | array contents=null, string encoding=utf-8)

Output text and immediately close the connection. If an array is passed the array dump will be sent.

Arguments

    contents=null (string | array)
    Data to output, null=write the response context values
    encoding=utf-8 (string)
    Character-encoding

Returns

IResponse
For method chaining

writeJson

IResponse $obj->writeJson(string | array data=null, string charset=utf-8)

Output JSON.

Arguments

    data=null (string | array)
    Data pack to send, null=send the response context values
    charset=utf-8 (string)
    Character-set, null=do not send any additional headers

Returns

IResponse
For method chaining

writeTemplate

void $obj->writeTemplate(string template)

Render a template and show the contents.

Arguments

    template (string)
    Template filename or a template dictionary key

Returns

void

writeX

IResponse $obj->writeX(string | array contents=null, string charset=utf-8)

Output text immediately without closing the connection. This is useful when a process takes time and you want to send messages meanwhile. If an array is passed the array dump will be sent.

Arguments

    contents=null (string | array)
    Data to output, null=write the response context values
    charset=utf-8 (string)
    Character-set, null=do not send any additional headers

Returns

IResponse
For method chaining