class SafeParam

Class representing a client input parameter

Provides a consistent interface for sanitizing and validating input values A value is considered null if it is an empty string or the string "null"

Constants

TYPE_RAW

A raw value that does no sanitizing or validating

TYPE_BOOL

A boolean value, see FILTER_VALIDATE_BOOLEAN

TYPE_INT

An integer value, see FILTER_VALIDATE_INT

private TYPE_INT_FIRST

TYPE_INT32

TYPE_INT16

TYPE_INT8

TYPE_UINT

An integer value, see FILTER_VALIDATE_UINT

TYPE_UINT32

TYPE_UINT16

TYPE_UINT8

private TYPE_INT_LAST

TYPE_FLOAT

A float value, see FILTER_VALIDATE_FLOAT

TYPE_RANDSTR

A value matching the format randomly generated by Andromeda

TYPE_ALPHANUM

An alphanumeric (and -_.) value

TYPE_NAME

A value representing a name, allows alphanumerics and -_'(). and space, max length 255

TYPE_EMAIL

An email address value, see FILTER_VALIDATE_EMAIL

TYPE_FSNAME

A file name value, see details

FILTER_FLAG_STRIP_LOW, max length 255, checks for directory traversal, forbids invalid characters \/?*:;}

TYPE_FSPATH

A filesystem path, see details

FILTER_FLAG_STRIP_LOW, max length 65535, forbids invalid characters ?*:;}

TYPE_HOSTNAME

A value containing a hostname, see FILTER_FLAG_STRIP_LOW, FILTER_VALIDATE_DOMAIN and FILTER_FLAG_HOSTNAME

TYPE_URL

A value containing a full URL, see FILTER_VALIDATE_URL

TYPE_TEXT

A string value with a max length of 65535, HTML-escapes special characters, see FILTER_SANITIZE_SPECIAL_CHARS

TYPE_OBJECT

A value that itself is a collection of SafeParams (an associative array)

TYPE_ARRAY

can be combined with any type to indicate an array of that type

TYPE_STRINGS

Properties

private $key
private $value

Methods

static string
GetTypeString(int $type)

Returns the string representing the given param type for printing

__construct(string $key, $value)

Construct a new SafeParam with the given key and value

string
GetKey()

Returns the key name of the SafeParam

GetRawValue()

Returns the raw value of the SafeParam - caution!

static callable
MaxLength(int $len)

Returns a function that checks the max length of the value, for use with GetValue

null|mixed|SafeParam[]|SafeParams
GetValue(int $type, array|null $values = null, callable|null $valfunc = null)

Gets the value of the parameter, doing filtering/validation, and JSON decoding for objects/arrays

Details

at line 139
static string GetTypeString(int $type)

Returns the string representing the given param type for printing

Parameters

int $type

Return Value

string

at line 153
__construct(string $key, $value)

Construct a new SafeParam with the given key and value

Parameters

string $key
$value

at line 164
string GetKey()

Returns the key name of the SafeParam

Return Value

string

at line 167
GetRawValue()

Returns the raw value of the SafeParam - caution!

at line 170
static callable MaxLength(int $len)

Returns a function that checks the max length of the value, for use with GetValue

Parameters

int $len

Return Value

callable

at line 186
null|mixed|SafeParam[]|SafeParams GetValue(int $type, array|null $values = null, callable|null $valfunc = null)

Gets the value of the parameter, doing filtering/validation, and JSON decoding for objects/arrays

If the parameter is an object type, a SafeParams object will be returned If the parameter is an array type, returns an array of SafeParams

Parameters

int $type

the requested type of the parameter

array|null $values

if not null, the value must be in this array

callable|null $valfunc

if not null, check the value against this function

Return Value

null|mixed|SafeParam[]|SafeParams

the value of the SafeParam

Exceptions

SafeParamInvalidException

if the value fails type validation

SafeParamInvalidEnumException

if the value is not in the given array

SafeParamUnknownTypeException

if an unknown type was requested