\Disco\classesData

Data class.

Provides easy wrapper around using HTTP data centric around the RESTful priciples PUT,POST,GET,DELETE.

Summary

Methods
Properties
Constants
__construct()
where()
get()
post()
delete()
put()
set()
remove()
all()
setCookie()
setRawCookie()
getCookie()
getComplexCookie()
hasCookie()
deleteCookie()
deleteAllCookies()
getAllCookies()
isPostedDataSizeOverLimit()
isPostedFileSizeOverLimit()
iniMaxPostSize()
iniMaxFileSize()
getCSRFToken()
getCSRFTokenInput()
validateCSRFToken()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
setData()
$putData
$deleteData
$workingDataType
$stream
N/A

Properties

$putData

$putData : array

Type

array — Holds the PUT data

$deleteData

$deleteData : array

Type

array — Holds the DELETE data

$workingDataType

$workingDataType : array

Type

array — Type of REST request

$stream

$stream : string

Type

string — Where are we parsing input data from

Methods

__construct()

__construct(string  $stream = 'php://input') : void

Construct PUT and DELETE data if the REQUEST_METHOD is PUT | DELETE.

Parameters

string $stream

The stream data is passed to PHP via the webserver, default : php://input.

where()

where(string|array  $k, string|null  $v = null) : string|boolean|integer|float

Determine if the specific $k data matches the found value using the regular expression $v.

Parameters

string|array $k

The key of the data, or an assoc array of key/condition pairs.

string|null $v

The regex pattern or default matching condition to use.

Returns

string|boolean|integer|float

get()

get(null|string  $g = null) : self|string|integer|float|boolean

Return a GET variable or if $g==null return $this and set method chain to use GET.

Parameters

null|string $g

The GET key to return.

Returns

self|string|integer|float|boolean

post()

post(null|string  $p = null) : self|string|integer|float|boolean

Return a POST variable or if $p==null return $this and set method chain to use POST.

Parameters

null|string $p

The POST key to return.

Returns

self|string|integer|float|boolean

delete()

delete(null|string  $d = null) : self|string|integer|float|boolean

Return a DELETE variable or if $d==null return $this and set method chain to use DELETE.

Parameters

null|string $d

The DELETE key to return.

Returns

self|string|integer|float|boolean

put()

put(null|string  $p = null) : self|string|integer|float|boolean

Return a PUT variable or if $p==null return $this and set method chain to use PUT.

Parameters

null|string $p

The PUT key to return.

Returns

self|string|integer|float|boolean

set()

set(null|string  $k = null, mixed  $v) : mixed

SET a selected type of REST variable.

Parameters

null|string $k

The key to set the $v with.

mixed $v

The value of $k.

Returns

mixed

remove()

remove(null|string  $k) : void

REMOVE a selected type of REST variable.

Parameters

null|string $k

The key to remove.

all()

all() : array

Return all of the selected type of REST data.

Returns

array

setCookie()

setCookie(string  $name, mixed  $value, integer|string  $time = '+30 days', string  $path = '', string  $domain = '', boolean  $secure = false, boolean  $httponly = false) : boolean

Set a cookie. Parameters are identical to http://php.net/manual/en/function.setcookie.php with the exception that time can be passed as a string or integer, strings are parsed to time using the `strtotime` function, and integers will always be added the current timestamp like `time() + $time`.

Parameters

string $name

The name of the cookie.

mixed $value

The value of the cookie. If you pass an array or an object it will be json encoded.

integer|string $time

The time to live for the cookie, default is +30 days.

string $path

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

string $domain

The (sub)domain that the cookie is available to.

boolean $secure

Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client

boolean $httponly

When TRUE the cookie will be made accessible only through the HTTP protocol. This means that the cookie won't be accessible by scripting languages, such as JavaScript

Returns

boolean

setRawCookie()

setRawCookie(string  $name, mixed  $value, integer|string  $time = '+30 days', string  $path = '', string  $domain = '', boolean  $secure = false, boolean  $httponly = false) : boolean

Set a raw cookie. Parameters are identical to http://php.net/manual/en/function.setcookie.php with the exception that time can be passed as a string or integer, strings are parsed to time using the `strtotime` function, and integers will always be added the current timestamp like `time() + $time`.

Parameters

string $name

The name of the cookie.

mixed $value

The value of the cookie. If you pass an array or an object it will be json encoded.

integer|string $time

The time to live for the cookie, default is +30 days.

string $path

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

string $domain

The (sub)domain that the cookie is available to.

boolean $secure

Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client

boolean $httponly

When TRUE the cookie will be made accessible only through the HTTP protocol. This means that the cookie won't be accessible by scripting languages, such as JavaScript

Returns

boolean

getCookie()

getCookie(string  $name) : mixed

Get a cookie value.

Parameters

string $name

The name of the cookie.

Returns

mixed —

The value of the cookie, or false if the cookie is not set.

getComplexCookie()

getComplexCookie(string  $name) : mixed

Get a complex cookie value (a cookie that is storing a JSON string).

Parameters

string $name

The name of the cookie.

Returns

mixed —

The JSON decoded (array) value of the cookie, or false if the cookie is not set.

hasCookie()

hasCookie(string  $name) : mixed

Is a cookie set.

Parameters

string $name

The name of the cookie.

Returns

mixed —

The value of the cookie, or false if the cookie is not set.

deleteCookie()

deleteCookie(string  $name) : boolean

Delete a cookie.

Parameters

string $name

The name of the cookie to delete.

Returns

boolean

deleteAllCookies()

deleteAllCookies(array  $except = array('PHPSESSID')) 

Delete all cookies.

Parameters

array $except

Delete all cookies except cookies with keys in the array. By default the array contains PHPSESSID, this avoids deleting the cookie that stores the session.

getAllCookies()

getAllCookies() : array

Get all the cookies.

Returns

array

isPostedDataSizeOverLimit()

isPostedDataSizeOverLimit() : boolean

Determine if posted data size exceeds the `max_post_size` ini limit.

Returns

boolean

isPostedFileSizeOverLimit()

isPostedFileSizeOverLimit() : boolean

Determine if posted files data size exceeds the `max_post_size` ini limit.

Returns

boolean

iniMaxPostSize()

iniMaxPostSize() : string

Human friendly file size of `post_max_size` ini value.

Returns

string

iniMaxFileSize()

iniMaxFileSize() : string

Human friendly file size of `upload_max_filesize` ini value.

Returns

string

getCSRFToken()

getCSRFToken(boolean  $reseed = false) : string

Get the value of the current CSRF token, if a token doesn't exist, it will be created. When the token is created it is stored in in the session variable identified by the key `CSRF_TOKEN_NAME` specified in `app/config/config.php`.

Parameters

boolean $reseed

Whether to regenerate a new CSRF Token even if one already exists in the session.

Returns

string —

The CSRF token.

getCSRFTokenInput()

getCSRFTokenInput() : string

Get a hidden input that contains the name and value of the CSRF Token.

Returns

string —

The input.

validateCSRFToken()

validateCSRFToken() : boolean

Validate the CSRF token passed with the request, either via HTTP Headers (where it should be identified by the header key `HTTP_X_CSRF_TOKEN`) or in the POST, PUT, or DELETE data (where it should be identified by the key `CSRF_TOKEN_NAME` specified in `app/config/config.php`).

Returns

boolean —

Whether the token validated.

setData()

setData(string  $type) : void

Set data of the selected type from the PUT or DELETE stream php://input .

We don't have to worry about handling GET or POST as Apache pre-parses those into $_GET & $_POST.

Parameters

string $type

the type of REST request either PUT|DELETE