Request

A wrapper around PHP request and server arrays. To get URL and path information and data from the request arrays. Artaengine always creates an instance or this class and passes it to the factory method or function as the first argument. It is possible to get the "Request" object anywhere in the application outside the factory context as: "$request = $globals['request'];"
Source
Request.php
Implements
IRequest
Depends on
Get , Post , Cookie , Session , Put , Delete , Upload , Inspect , IRequestArray , Validate
Extends
RequestUrl

Properties

Delete

$obj->Delete

An instance of class Delete (wrapper around request DELETE method). Instantiation is done on demand, at the first time this property is used.

See also
IRequestArray

Get

$obj->Get

An instance of class Get (wrapper around request get method). Instantiation is done on demand, at the first time this property is used.

See also
IRequestArray

Post

$obj->Post

An instance of class Post (wrapper around request post method). Instantiation is done on demand, at the first time this property is used.

See also
IRequestArray

Put

$obj->Put

An instance of class Put (wrapper around PUT cookie). Instantiation is done on demand, at the first time this property is used.

See also
IRequestArray

Session

$obj->Session

An instance of class Session (wrapper around request session). Instantiation is done on demand, at the first time this property is used.

See also
ISession

Upload

$obj->Upload

An instance of class Upload (wrapper around file uploads). Instantiation is done on demand, at the first time this property is used.

See also
IUpload

Static Methods

joinUrl

string Request::joinUrl(array url)

Join parts of a URL into a string.

Arguments

    url (array)
    Url parts
    {
        string       protocol : URL protocol e.g. "http" or "https",
        string       scheme :   URL protocol e.g. "http" or "https",
        string       user :     user-name,
        string       pass :     user-password,
        string       host :     URL host,
        string       port :     port,
        string|array path :     URL path or paths or list of paths,
        string|array query :    query-string or params as {key: value},
        string       fragment : URL fragment part,
    }
    

Returns

string
URL

queryString

string|array Request::queryString(string key=null)

Get query string parameter(s) of current URL.

Arguments

    key=null (string)
    string=return the value for the key, null=return an array of all parameters

Returns

string|array
Query string parameters(s), null if key not exists

queryStringCount

int Request::queryStringCount()

Get number of the query string parameters in current URL.

Returns

int
Number of the query string parameters in current URL

queryStrings

string Request::queryStrings(string glue='&')

Get the query string parameters as a string.

Arguments

    glue='&' (string)
    Glue between the "key=value"s

Returns

string
A string of the query string parameters

toQueryString

string Request::toQueryString(string glue='&')

Turn an array into a URL encoded query string.

Arguments

    glue='&' (string)
    Glue between the "key=value"s

Returns

string
A string of the query string parameters

filterValue

mixed Request::filterValue(mixed value)

Get value after passing it from the filter set to request. Values retrieved from IRequestArray and IBinder objects respect the filter by passing the values through this method.

Arguments

    value (mixed)
    the value to be passed thorough filter

Returns

mixed
the value returned by the filter

headers

array|string Request::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 Request::httpVersion()

Get HTTP version.

Returns

string
HTTP version.

input

mixed Request::input(array source, string key, mixed default=null, const type=null)

Get a value from an array. This method is used by the "IRequestArray" instances and "IRequest" methods: "get()", "post()", "session()" and "cookie()".

Arguments

    source (array)
    Source array
    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

inspect

void|array Request::inspect(bool print=true)

Dumps request variables.

Arguments

    print=true (bool)
    false=returns an array of request

Returns

void|array
If print=false returns an array of request vars

ip

string Request::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 Request::isAjax()

Request is from AJAX.

Returns

bool
true=request is AJAX

isDelete

bool Request::isDelete()

Check if the used HTTP request method is delete.

Returns

bool
true=request mthod is delete

isGet

bool Request::isGet()

Check if the used HTTP request method is get.

Returns

bool
true=request mthod is get

isHead

bool Request::isHead()

Check if the used HTTP request method is head.

Returns

bool
true=request mthod is head

isOptions

bool Request::isOptions()

Check if the used HTTP request method is options.

Returns

bool
true=request mthod is options

isPost

bool Request::isPost()

Check if the used HTTP request method is post.

Returns

bool
true=request mthod is post

isPut

bool Request::isPut()

Check if the used HTTP request method is put.

Returns

bool
true=request mthod is put

isSecure

bool Request::isSecure()

Check if request is a secured one.

Returns

bool
true=is secure

like

array Request::like(array source, string key)

Get {key:value,} from array "source" where the keys in source contain the "key" string inside them. This method is used by the "IRequestArray" instances.

Since
Artaengine 1.2.2

Arguments

    source (array)
    Source array
    key (string)
    String to be searched in "source" keys

Returns

array
{key:value,} a subset of "source" where keys contains "key"

meta

array|string Request::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 Request::port()

Get port.

Returns

string
Port

protocol

string Request::protocol()

Get protocol.

Returns

string
"http" or "https"

setFilter

void Request::setFilter(string filter)

Set a function or static class method to filter request values before being returned. Note that data types passed to the filter are not always strings, it is up to the filter to check the data types.

Arguments

    filter (string)
    function name or static method name 'Class::filterMethod' null=disable filter

Returns

void

ua

string Request::ua()

Get User-agent.

Returns

string
User-agent

with

array Request::with(array source, string key, bool remove)

Get {key:value,} from array "source" where the keys in source start with the "key". This method is used by the "IRequestArray" instances.

Since
Artaengine 1.2.0

Arguments

    source (array)
    Source array
    key (string)
    String to be searched in "source" keys
    remove (bool)
    true=remove "key" from the keys in the returned array

Returns

array
{key:value,} a subset of "source" where keys start with "key"

Methods

__construct

Request $obj = new Request(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

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)

getRealPaths

string $obj->getRealPaths()

This is normally the same as paths, unless on local. e.g. if "test" is a real directory then for URL "http://localhost/test/path1/path2" the real path is "test/path1/path2" but the path is "path1/path2".

Returns

string
Server URL

getServerUrl

string $obj->getServerUrl()

This is normally the same as base URL, unless on local. e.g. if "test" is a real directory then for URL "http://localhost/test" the server URL is "http://localhost/" but the base URL is "http://localhost/test".

Returns

string
Server URL

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

__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;"

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

getAuthenticateData

boolean|array $obj->getAuthenticateData()

Get simple or digest authenticate data.

Returns

boolean|array
false=failed, array=authenticate data

httpDigestParse

bool|array $obj->httpDigestParse(string value)

Parse the http auth header value.

Arguments

    value (string)
    http auth header value

Returns

bool|array
parsed data or false

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