27 'string' => self::STRING,
28 'istring' => self::ISTRING,
30 'itext' => self::ITEXT,
32 'float' => self::FLOAT,
34 'lookup' => self::LOOKUP,
35 'list' => self::ALIST,
37 'mixed' => self::MIXED
46 self::ISTRING =>
true,
61 final public function parse($var, $type, $allow_null =
false) {
62 if (is_string($type)) {
70 if ($allow_null && $var === null)
return null;
78 if (!is_string($var))
break;
79 if ($type == self::ISTRING || $type == self::ITEXT) $var = strtolower($var);
82 if (!is_int($var))
break;
85 if (!is_float($var))
break;
88 if (!is_bool($var))
break;
93 if (!is_array($var))
break;
94 if ($type === self::LOOKUP) {
95 foreach ($var as $k)
if ($k !==
true) $this->
error(
'Lookup table contains value other than true');
96 } elseif ($type === self::ALIST) {
97 $keys = array_keys($var);
98 if (array_keys($keys) !== $keys) $this->
error(
'Indices for list are not uniform');
138 $vtype = gettype($var);
148 if (!isset($lookup[$type]))
return 'unknown';
149 return $lookup[$type];
errorInconsistent($class, $type)
Throws an inconsistency exception.
static $types
Lookup table of allowed types.
parse($var, $type, $allow_null=false)
Validate a variable according to type.
Exception type for HTMLPurifier_VarParser.
errorGeneric($var, $type)
Generic error for if a type didn't work.
static $stringTypes
Lookup table of types that are string, and can have aliases or allowed value lists.
error($msg)
Throws an exception.
Global exception class for HTML Purifier; any exceptions we throw are from here.
Parses string representations into their corresponding native PHP variable type.
parseImplementation($var, $type, $allow_null)
Actually implements the parsing.
static getTypeName($type)