IRequest

Interface for the Request class.
Source
IRequest.php
Implementations
Request

Static Methods

headers

array|string IRequest::headers(string header=null)

Get all request HTTP headers (an array) or the value of a specific header.

Arguments

    header=null (string)
    If provided then returns the value of the header

Returns

array|string
HTTP headers or the value of a header or null if header not exists

httpVersion

string IRequest::httpVersion()

Get HTTP version.

Returns

string
HTTP version.

ip

string IRequest::ip()

Tries to get client's IP as best as it can. Tries to get the IP from HTTP headers "Client-IP", "X-Forwarded-For", "X-Forwarded", "Forwarded-For", "Forwarded" or "$_SERVER[REMOTE_ADDR]".

Returns

string
IP address

isAjax

bool IRequest::isAjax()

Request is from AJAX.

Returns

bool
true=request is AJAX

isGet

bool IRequest::isGet()

Check if the used HTTP request method is get.

Returns

bool
true=request mthod is get

isPost

bool IRequest::isPost()

Check if the used HTTP request method is post.

Returns

bool
true=request mthod is post

isSecure

bool IRequest::isSecure()

Check if request is a secured one.

Returns

bool
true=is secure

meta

array|string IRequest::meta(string key=null)

Get the "$_SERVER" array or the value of a "$_SERVER" key.

Arguments

    key=null (string)
    If provided then returns the value of the key in "$_SERVER"

Returns

array|string
"$_SERVER" or a value of a "$_SERVER" key or null if key not exists

port

string IRequest::port()

Get port.

Returns

string
Port

protocol

string IRequest::protocol()

Get protocol.

Returns

string
"http" or "https"

ua

string IRequest::ua()

Get User-agent.

Returns

string
User-agent

Methods

__construct

IRequest $obj = new IRequest(string pathKey=null)

Create an "IRequest" instance. The instance will identify the URL paths, this paths are crucial for the URL to factory mappings.

Arguments

    pathKey=null (string)
    The $_GET key which contains URL path when set in the web-server rewrite rules. e.g. Apache: "RewriteRule ^(.*)$ start.php?q=$1 [L,QSA]" pathKey="q". null=use the real URL for getting paths

Returns

void

__get

IRequestArray __get(string class)

Invoke an "IRequestArray" instance. Usage: "$email = $request->Get->get('email', 'nothing', T::EMAIL);"

Arguments

    class (string)
    Name of a class implementing "IRequestArray" e.g. "Get, Post, Session, Cookie"

Returns

IRequestArray
e.g. "$email = $request->Post->email;"

baseUrl

string $obj->baseUrl()

Get base URL. In an Artaengine App the base URL can be obtained from the "BASE_URL" too.

Returns

string
Base URL (without query string)

currentUrl

string $obj->currentUrl()

Get current URL.

Returns

string
Current URL (without query string)

get

mixed $obj->get(string key, mixed default=null, const type=null)

Get a value from "$_GET". This is a shortcut for "$request->Get->get()".

Arguments

    key (string)
    The key to get it's value
    default=null (mixed)
    The default-value to be returned if key not exists or value is invalid
    type=null (const)
    Set to an Artaengine type constant such as "INT", "T::INT", "T::EMAIL", etc. to validate or cast the returned value

Returns

mixed
The value set to the key or the default-value/"null" if key not exists

isRoot

void $obj->isRoot()

Is current URL root (has no path) or in other words is current URL = base URL.

Returns

void

makeRelativeUrl

string $obj->makeRelativeUrl(string newPath=null, string path='base')

Create URLs relative to the base URL or current URL (query string not included). The new path can be glued to "base"(base URL) or "current"(current URL).

Arguments

    newPath=null (string)
    The new relative path
    path='base' (string)
    Can be either "base" or "current"

Returns

string
The new URL

path

string|array $obj->path(int i=null)

Get path(s) of current URL.

Arguments

    i=null (int)
    int=return the i'th path (zero based), null=return an array of all paths

Returns

string|array
URL path(s), null if index not exists

pathCount

int $obj->pathCount()

Get the number of paths inside current URL.

Returns

int
Number of paths

paths

string $obj->paths()

Get all paths of current URL as string.

Returns

string
URL paths

post

mixed $obj->post(string key, mixed default=null, const type=null)

Get a value from "$_POST". This is a shortcut for "$request->Post->get()".

Arguments

    key (string)
    The key to get it's value
    default=null (mixed)
    The default-value to be returned if key not exists or value is invalid
    type=null (const)
    Set to an Artaengine type constant such as "INT", "T::INT", "T::EMAIL", etc. to validate or cast the returned value

Returns

mixed
The value set to the key or the default-value/"null" if key not exists

session

mixed $obj->session(string key, mixed default=null, const type=null)

Get a value from "$_SESSION". This is a shortcut for "$request->Session->get()". Session starting is managed automatically.

Arguments

    key (string)
    The key to get it's value
    default=null (mixed)
    The default-value to be returned if key not exists or value is invalid
    type=null (const)
    Set to an Artaengine type constant such as "INT", "T::INT", "T::EMAIL", etc. to validate or cast the returned value

Returns

mixed
The value set to the key or the default-value/"null" if key not exists