ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_VarParser_Flexible Class Reference

Performs safe variable parsing based on types which can be used by users. More...

+ Inheritance diagram for HTMLPurifier_VarParser_Flexible:
+ Collaboration diagram for HTMLPurifier_VarParser_Flexible:

Protected Member Functions

 parseImplementation ($var, $type, $allow_null)
 Actually implements the parsing.
- Protected Member Functions inherited from HTMLPurifier_VarParser
 error ($msg)
 Throws an exception.
 errorInconsistent ($class, $type)
 Throws an inconsistency exception.
 errorGeneric ($var, $type)
 Generic error for if a type didn't work.

Additional Inherited Members

- Public Member Functions inherited from HTMLPurifier_VarParser
 parse ($var, $type, $allow_null=false)
 Validate a variable according to type.
- Static Public Member Functions inherited from HTMLPurifier_VarParser
static getTypeName ($type)
- Data Fields inherited from HTMLPurifier_VarParser
const STRING = 1
const ISTRING = 2
const TEXT = 3
const ITEXT = 4
const INT = 5
const FLOAT = 6
const BOOL = 7
const LOOKUP = 8
const ALIST = 9
const HASH = 10
const MIXED = 11
- Static Public Attributes inherited from HTMLPurifier_VarParser
static $types
 Lookup table of allowed types.
static $stringTypes
 Lookup table of types that are string, and can have aliases or allowed value lists.

Detailed Description

Performs safe variable parsing based on types which can be used by users.

This may not be able to represent all possible data inputs, however.

Definition at line 8 of file Flexible.php.

Member Function Documentation

HTMLPurifier_VarParser_Flexible::parseImplementation (   $var,
  $type,
  $allow_null 
)
protected

Actually implements the parsing.

Base implementation is to not do anything to $var. Subclasses should overload this!

Reimplemented from HTMLPurifier_VarParser.

Definition at line 11 of file Flexible.php.

References $key, $type, elseif(), HTMLPurifier_VarParser\errorGeneric(), and HTMLPurifier_VarParser\errorInconsistent().

{
if ($allow_null && $var === null) return null;
switch ($type) {
// Note: if code "breaks" from the switch, it triggers a generic
// exception to be thrown. Specific errors can be specifically
// done here.
case self::MIXED :
case self::ISTRING :
case self::STRING :
case self::TEXT :
case self::ITEXT :
return $var;
case self::INT :
if (is_string($var) && ctype_digit($var)) $var = (int) $var;
return $var;
case self::FLOAT :
if ((is_string($var) && is_numeric($var)) || is_int($var)) $var = (float) $var;
return $var;
case self::BOOL :
if (is_int($var) && ($var === 0 || $var === 1)) {
$var = (bool) $var;
} elseif (is_string($var)) {
if ($var == 'on' || $var == 'true' || $var == '1') {
$var = true;
} elseif ($var == 'off' || $var == 'false' || $var == '0') {
$var = false;
} else {
throw new HTMLPurifier_VarParserException("Unrecognized value '$var' for $type");
}
}
return $var;
case self::ALIST :
case self::HASH :
case self::LOOKUP :
if (is_string($var)) {
// special case: technically, this is an array with
// a single empty string item, but having an empty
// array is more intuitive
if ($var == '') return array();
if (strpos($var, "\n") === false && strpos($var, "\r") === false) {
// simplistic string to array method that only works
// for simple lists of tag names or alphanumeric characters
$var = explode(',',$var);
} else {
$var = preg_split('/(,|[\n\r]+)/', $var);
}
// remove spaces
foreach ($var as $i => $j) $var[$i] = trim($j);
if ($type === self::HASH) {
// key:value,key2:value2
$nvar = array();
foreach ($var as $keypair) {
$c = explode(':', $keypair, 2);
if (!isset($c[1])) continue;
$nvar[$c[0]] = $c[1];
}
$var = $nvar;
}
}
if (!is_array($var)) break;
$keys = array_keys($var);
if ($keys === array_keys($keys)) {
if ($type == self::ALIST) return $var;
elseif ($type == self::LOOKUP) {
$new = array();
foreach ($var as $key) {
$new[$key] = true;
}
return $new;
} else break;
}
if ($type === self::LOOKUP) {
foreach ($var as $key => $value) {
$var[$key] = true;
}
}
return $var;
default:
$this->errorInconsistent(__CLASS__, $type);
}
$this->errorGeneric($var, $type);
}

+ Here is the call graph for this function:


The documentation for this class was generated from the following file: