Class TypeValidator

Description

Use the static TypeValidator class to validate an associated array of parameters against a type definition map.

Located in /TypeValidator.php (line 37)


	
			
Variable Summary
 static array $isBool
 static array $isType
Method Summary
 static void cast (mixed &$value, string $type)
 static array check (array $param, array $map)
 static void checkField (array $field)
 static void checkParam (array &$param, array $field)
 static bool checkType (mixed $value, string $type)
Variables
static array $isBool = array(0, 1, -1, "0", "1", "-1", "true", "TRUE", "false", "FALSE") (line 51)
  • var: Valid boolean values
  • access: public
static array $isType = array("bool", "int", "float", "date", "string", "array", "object") (line 44)
  • var: Valid type identifiers
  • access: public
Methods
static cast (line 215)

Convert the type of a variable if necessary.

  • access: protected
static void cast (mixed &$value, string $type)
static check (line 83)

Validate an associated array of parameters against a type definition map.

Normally, you don't need to call this function directly. Ist's called from every select(), insert(), update() and delete() function. See the IConnector interface.

A map is an array of type definitions. A type definition is an array with two or three elements. Format:

 $map[] = array(name, type[, default]);
 name:    The key of an element in the associated array to validate.
 type:    A type identifier, see TypeValidator::$isType.
 default: An optional default value. Can be of any type, also null.

If the type of $param[name] is wrong and can't be converted to the required type, an exception is thrown. If $param[name] doesn't exist or is null, the optional default value is used or - if no default value is given - an exception is thrown. Exsample:

  • return: A valid (and possibly modified) associated array of parameters.
  • throws: Exception when $param doesn't match the type definition $map.
  • access: public
static array check (array $param, array $map)
  • array $param: An associated array of parameters to validate.
  • array $map: An array of type definitions.
static checkField (line 110)

Checks if a type definition is valid. If not, an exception is thrown.

  • throws: Exception when an invalid type definition is given.
  • access: protected
static void checkField (array $field)
  • array $field: The definition of a single field.
static checkParam (line 148)

Check if an associated array of parameters match a type definition.

If not, an exception is thrown.

Valid parameters may be are converted or substituted to match the field definitien.

  • throws: Exception when $param doesn't match the type definition.
  • access: protected
static void checkParam (array &$param, array $field)
  • array &$param: An associated array of parameters to validate.
  • array $field: A type definition array.
static checkType (line 190)

Check the type of a variable. A value of null allways returns false.

  • return: true if the value has the correct type, false otherwise.
  • access: protected
static bool checkType (mixed $value, string $type)

Documentation generated on Wed, 03 Jun 2009 12:41:56 +0200 by phpDocumentor 1.4.1