Class RaxanDataSanitizer

Description

Provides APIs to filter, sanitizer and format user inputs and file uploads

Located in /raxan.datasanitizer.php (line 13)



                    
Variable Summary
static mixed $badCharacters
static mixed $validators
mixed $_charset
mixed $_data
mixed $_date
mixed $_directInp
Method Summary
static null addDataValidator ( $name, mixed $pattern, string $key)
RaxanDataSanitizer __construct ([ $array = null], [ $charset = null])
void addValidator ( $name,  $pattern)
string alphanumericVal ( $key)
mixed dateVal ( $key, [string $format = null])
string emailVal ( $key)
void enableDirectInput ([boolean $state = true])
string escapeVal ( $key)
string fileContent (string $fld)
boolean fileCopy (string $fld, string $dest)
int fileCount ()
boolean fileImageResample (string $fld,  $w,  $h, [ $type = null])
mixed fileImageSize (string $fld)
boolean fileMove (string $fld, string $dest)
string fileOrigName (string $fld)
integer fileSize (string $fld)
string fileTmpName (string $fld)
string fileType (string $fld)
string fileUploadError (string $fld)
array filterValues ([mixed $keyFields = null])
float floatVal ( $key, [ $decimal = null])
string formatDate (string $key, [string $format = null])
string formatMoney (string $key, [int $decimal = null], [string $symbol = null])
string formatNumber (string $key, [int $decimal = null])
string htmlVal (string $key, [string $allowable = null], [string $allowStyle = true])
int intVal ( $key)
boolean isDate (string $key, [string $format = null])
boolean isEmail ( $key)
boolean isNumeric (mixed $key, [float $min = null], [float $max = null])
boolean isUrl ( $key)
int length ( $key)
string matchVal (string $key, [string $pattern = '/[a-zA-Z0-9-.]/'])
string textVal (string $key, [int $maxlength = null])
int timestampVal ( $key)
string urlVal (string $key, [boolean $encoded = false])
mixed value ( $key)
void __call ( $name,  $args)
String __get ( $name)
String __set ( $name,  $value)
Variables
static mixed $badCharacters = array("\r","\n","\t","\x00","\x1a") (line 16)
  • access: protected
static mixed $validators = array() (line 15)
  • access: protected
mixed $_charset (line 21)
  • access: protected
mixed $_data (line 18)
  • access: protected
mixed $_date (line 19)
  • access: protected
mixed $_directInp (line 20)
  • access: protected
Methods
static addDataValidator (line 598)

Adds a custom data validator using regex patterns or callback function

  • access: public
static null addDataValidator ( $name, mixed $pattern, string $key)
  • string $key: Key name or input value (direct input must be enabled)
  • mixed $pattern: Optional. Regex pattern or a callback function
  • $name
Constructor __construct (line 24)
  • access: public
RaxanDataSanitizer __construct ([ $array = null], [ $charset = null])
  • $array
  • $charset
addValidator (line 72)

Adds a custom data validator using regex patterns or callback function

Used as a wrapper to the RaxanDataSanitizer::addDataValidator() static method

  • access: public
void addValidator ( $name,  $pattern)
  • $name
  • $pattern
alphanumericVal (line 80)

Returns an alphanumeric value for the specified field name

  • return: If input is an array then an array of alphanumeric values will be returned
  • access: public
string alphanumericVal ( $key)
  • $key
dateVal (line 94)

Returns a date value for the specified field name

  • return: Returns a date/time string value based on the $format parameter or null if value is not a valid date. If input is an array then an array of date values is returned
  • access: public
mixed dateVal ( $key, [string $format = null])
  • string $format
  • $key
emailVal (line 113)

Returns sanitized email address for the selected field

  • return: Returns sanitized email address or an empty string if input value is not a valid email address. If input is an array then an array of email values is returned
  • access: public
string emailVal ( $key)
  • $key
enableDirectInput (line 105)

Enables direct data input. This will allow values to be passed directly to validator functions.

  • access: public
  • example: example not found
void enableDirectInput ([boolean $state = true])
  • boolean $state: Defaults to true
escapeVal (line 126)

Returns text with special xml/html characters encoded for the selected field

  • return: If input is an array then an array of escaped values is returned
  • access: public
string escapeVal ( $key)
  • $key
fileContent (line 140)

Returns the content of an uploaded file based on the selected field name

  • access: public
string fileContent (string $fld)
  • string $fld: Form element field name
fileCopy (line 151)

Copies an uploaded files (based on the selected field name) to the specified destination.

  • access: public
boolean fileCopy (string $fld, string $dest)
  • string $fld: Form element field name
  • string $dest: Destination path and file name
fileCount (line 161)

Returns a total number of file uploaded

  • access: public
int fileCount ()
fileImageResample (line 182)

Resamples (convert/resize) the uploaded image. You can specify a new width, height and type

boolean fileImageResample (string $fld,  $w,  $h, [ $type = null])
  • string $fld: Form element field name
  • $w
  • $h
  • $type
fileImageSize (line 170)

Returns an array containing the width, height and type for the uploaded image file

  • return: Array or null on error
  • access: public
mixed fileImageSize (string $fld)
  • string $fld: Form element field name
fileMove (line 194)

Moves an uploaded files (based on the selected field name) to the specified destination.

  • access: public
boolean fileMove (string $fld, string $dest)
  • string $fld: Form element field name
  • string $dest: Destination path and file name
fileOrigName (line 206)

Returns the original name of the uploaded file based on the selected field name

  • access: public
string fileOrigName (string $fld)
  • string $fld: Form element field name
fileSize (line 216)

Returns the size of the uploaded file based on the selected field name

  • access: public
integer fileSize (string $fld)
  • string $fld: Form element field name
fileTmpName (line 243)

Returns the temporary file name and path of the uploaded file based on the selected field name

  • access: public
string fileTmpName (string $fld)
  • string $fld: Form element field name
fileType (line 225)

Returns the file type (as reported by browser) of an uploaded file based on the selected field name

  • access: public
string fileType (string $fld)
  • string $fld: Form element field name
fileUploadError (line 234)

Returns the file upload error code for uploaded file

  • access: public
string fileUploadError (string $fld)
  • string $fld: Form element field name
filterValues (line 252)

Returns associative array of filtered/sanitized values

  • access: public
array filterValues ([mixed $keyFields = null])
  • mixed $keyFields: Optional. Comma (,) delimitted key/field names or associative array of field names and filter type. Default to all keys/fields with textVal filter applied
floatVal (line 284)

Converts input value/key to a float value

  • return: Returns float if value is numeric or null if there was an error. If input is an array then an array of float values is returned
  • access: public
float floatVal ( $key, [ $decimal = null])
  • $key
  • $decimal
formatDate (line 303)

Returns formated date value

  • return: If input is an array then an array of formated date values is returned
  • access: public
string formatDate (string $key, [string $format = null])
  • string $key: Key name or input value (direct input must be enabled)
  • string $format: Date format
formatMoney (line 346)

Returns formatted money value based on locale settings

  • return: If input is an array then an array of formated values is returned
  • access: public
string formatMoney (string $key, [int $decimal = null], [string $symbol = null])
  • string $key: Key name or input value (direct input must be enabled)
  • int $decimal: Optional. Total number of decimal places to return
  • string $symbol: Optional. Currency symbol
formatNumber (line 373)

Returns formatted number value based on locale settings

  • return: If input is an array then an array of formatted numeric values is returned
  • access: public
string formatNumber (string $key, [int $decimal = null])
  • string $key: Key name or input value (direct input must be enabled)
  • int $decimal: Optional. Total number of decimal places to return
htmlVal (line 391)

Sanitized html by removing javascript tags and inline events

  • return: If input is an array then an array of html values is returned
  • access: public
string htmlVal (string $key, [string $allowable = null], [string $allowStyle = true])
  • string $key: Key name or input value (direct input must be enabled)
  • string $allowable: Optional. Allowable html tags. Example <p><a>
  • string $allowStyle: Optional. Allow css styles inside html. Defaults to true
intVal (line 424)

Converts input value/key to an integer value

  • return: Returns interger if value is numeric or null if there was an error
  • access: public
int intVal ( $key)
  • $key
isDate (line 439)

Returns true if the selected field contains a valid date

  • access: public
boolean isDate (string $key, [string $format = null])
  • string $key: Key name or input value (direct input must be enabled)
  • string $format: Optional date input format. Accepts the same format as formatDate()
isEmail (line 454)

Returns true if the selected field contains a valid email address

  • access: public
boolean isEmail ( $key)
  • $key
isNumeric (line 468)

Returns true if the selected field is numeric

  • access: public
boolean isNumeric (mixed $key, [float $min = null], [float $max = null])
  • mixed $key: Key field name or value
  • float $min: Optional. Minimum value
  • float $max: Optional. Maximum value
isUrl (line 478)

Returns true if the selected field contains a valid url

  • access: public
boolean isUrl ( $key)
  • $key
length (line 494)

Returns the length of the speicifed field value

  • access: public
int length ( $key)
  • $key
matchVal (line 504)

Returns matched characters

  • access: public
string matchVal (string $key, [string $pattern = '/[a-zA-Z0-9-.]/'])
  • string $key: Key name or input value (direct input must be enabled)
  • string $pattern: Optional Regex pattern. Defaults to /[a-zA-Z0-9-.]/
setDataArray (line 517)

Sets the array source for the sanitizer

  • access: public
RaxanDataSanitizer setDataArray ( $array)
  • $array
textVal (line 528)

Remove html tags from input values

  • access: public
string textVal (string $key, [int $maxlength = null])
  • string $key: Key name or input value (direct input must be enabled)
  • int $maxlength: Optional. Length of text value to be returned
timestampVal (line 545)

Converts input value/key to a valid timestamp

  • return: Returns timestamp if value is a valid datetime string or null if there was an error
  • access: public
int timestampVal ( $key)
  • $key
urlVal (line 566)

Returns sanitized url for the selected field

  • access: public
string urlVal (string $key, [boolean $encoded = false])
  • string $key: Key name or input value (direct input must be enabled)
  • boolean $encoded: Optional. Encode url string. Defaults to false
value (line 583)

Returns a value based on the specified key

  • access: public
mixed value ( $key)
  • $key
__call (line 30)
  • access: public
void __call ( $name,  $args)
  • $name
  • $args
__get (line 53)

Returns the sanitized text for the specified key. All html charcters will be removed.

  • access: public
String __get ( $name)
  • $name
__set (line 64)

Sets the value for a key to be sanitized or formatted.

Example: $format->keyName = 'Mary Jane
'; echo $format->textVal('keyName');

  • access: public
String __set ( $name,  $value)
  • $name
  • $value