\TriTan\CommonSanitizer

Summary

Methods
Properties
Constants
__construct()
validateItems()
items()
item()
validateItem()
key()
username()
removeAccents()
$regexes
No constants found
No protected methods found
No protected properties found
N/A
addError()
$validate
$sanitize
$required
$errors
$corrects
$fields
$hook
N/A

Properties

$regexes

$regexes : 

Type

$validate

$validate : 

Type

$sanitize

$sanitize : 

Type

$required

$required : 

Type

$errors

$errors : 

Type

$corrects

$corrects : 

Type

$fields

$fields : 

Type

$hook

$hook : 

Type

Methods

validateItems()

validateItems(array  $items) : boolean

Validates an array of items (if needed).

Parameters

array $items

Items to validate.

Returns

boolean —

True if valid, false otherwise.

items()

items(array  $items, string  $context = 'save') : array

Sanitizes an array of items according to the $this->sanitize[].

Sanitize will be standard of type string, but can also be specified. For ease of use, this syntax is accepted:

 $sanitize = array('fieldname', 'otherfieldname' => 'float');
 $this->items($sanitize);

Parameters

array $items

Items to sanitize.

string $context

The context for which the string is being sanitized.

Returns

array —

Sanitized items.

item()

item(mixed  $item, string  $type = 'string', string  $context = 'save') : string|null

Sanitizes an item according to type.

Parameters

mixed $item

Item to sanitize.

string $type

Item type (i.e. string, float, int, etc.).

string $context

The context for which the string is being sanitized.

Returns

string|null —

Sanitized string or null if item is empty.

validateItem()

validateItem(mixed  $item, string  $type) : boolean

Validates a single item according to $type.

Parameters

mixed $item

Item to validate.

string $type

Item type (i.e. string, float, int, etc.).

Returns

boolean —

True if valid, false otherwise.

key()

key(string  $key) : string

Sanitizes a string key.

Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed.

Uses sanitize_key filter hook.

Parameters

string $key

String key

Returns

string —

Sanitized key

username()

username(string  $username, boolean  $strict = false) : string

Sanitizes a username, stripping out unsafe characters.

Removes tags, octets, entities, and if strict is enabled, will only keep alphanumeric, _, space, ., -, @. After sanitizing, it passes the username, raw username (the username in the parameter), and the value of $strict as parameters for the sanitize_user filter.

Parameters

string $username

The username to be sanitized.

boolean $strict

If set, limits $username to specific characters. Default false.

Returns

string —

The sanitized username, after passing through filters.

removeAccents()

removeAccents(\TriTan\Common\string  $string,   $encoding = 'UTF-8') 

Parameters

\TriTan\Common\string $string
$encoding

addError()

addError(  $field,   $type = 'string') 

Adds an error to the errors array.

Parameters

$field
$type