\cge_param

A set of utilities for cleaning input parameters.

Summary

Methods
Properties
Constants
exists()
get_html()
get_int()
get_bool()
get_empty_string()
get_string()
get_float()
get_string_array()
get_separated_date()
get_date()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

exists()

exists(array  $params, string  $key) : boolean

A convenience method to test if a key exists in the input array.

Parameters

array $params

An associative array of input params

string $key

The key to the associative array

Returns

boolean

get_html()

get_html(array  $params, string  $key, string  $dflt = null) : string

Get safe HTML from an input parameter.

This method uses htmlawed to clean input HTML.

Parameters

array $params

An associative array of input params

string $key

The key to the associative array

string $dflt

The default value to use if the key does not exist in the $params aray.

Returns

string

get_int()

get_int(array  $params, string  $key, integer  $dflt = null) : integer|null

Get a safe integer from an input parameter.

Parameters

array $params

An associative array of input params

string $key

The key to the associative array

integer $dflt

The default value to use if the key does not exist in the $params aray.

Returns

integer|null

get_bool()

get_bool(array  $params, string  $key, boolean  $dflt = false) 

Get a safe boolean from an input parameter.

This method can accept boolean strings like yes, no, true, false, on, off.

Parameters

array $params

An associative array of input params

string $key

The key to the associative array

boolean $dflt

The default value to use if the key does not exist in the $params aray.

get_empty_string()

get_empty_string(array  $params, string  $key, string  $dflt = null) 

Get a safe string from an input parameter.

This is similar to the get_string method except that if the $dflt is null, and the parameter does not exist, then null will be returned.

Parameters

array $params

An associative array of input params

string $key

The key to the associative array

string $dflt

The default value to use if the key does not exist in the $params aray.

get_string()

get_string(array  $params, string  $key, string  $dflt = null) 

Get a safe string from an input parameter.

The string is stripped of any html code, and high or low bytes.

Parameters

array $params

An associative array of input params

string $key

The key to the associative array

string $dflt

The default value to use if the key does not exist in the $params aray.

get_float()

get_float(array  $params, string  $key, float  $dflt = null) 

Get a safe float from an input parameter.

Parameters

array $params

An associative array of input params

string $key

The key to the associative array

float $dflt

The default value to use if the key does not exist in the $params aray.

get_string_array()

get_string_array(array  $params, string  $key, array<mixed,string>  $dflt = null) 

Get a safe array of strings from an input parameter that is an array.

keys and values are cleaned.

Parameters

array $params

An associative array of input params

string $key

The key to the associative array

array<mixed,string> $dflt

The default value to use if the key does not exist in the $params aray.

get_separated_date()

get_separated_date(array  $params, string  $prefix, integer  $dflt = null) : integer

Get a unix timestamp from separate month, day and year fields.

This method is useful for converting dates a user entered into separate month day and year fields into a unix timestamp. i.e: if using the smarty {html_select_date} field for gathering dates.

This method assumes that there will be separate fields in the params array who's values are integers, and the key begins with the provided prefix and ends with _Month, _Day, and _Year respectively.

Note, if the year parameter does not exist in the params array, but month and day do... then the current year is used.

Parameters

array $params
string $prefix

The common prefix for the separate month, day and year parameters

integer $dflt

The optional default value.

Returns

integer —

A unix timestamp representing the day found, at midnight.

get_date()

get_date(array  $params, string  $key, integer  $dflt = null) 

Get a unix timestamp from a input text or date field.

assumes value from a date element, or some other string that can be parsed by strtotime

Parameters

array $params
string $key

The key to the associative array

integer $dflt

The default timestamp value to use if the key does not exist in the $params aray.