Reorganize VarParser; there may be multiple implementations.
[htmlpurifier.git] / library / HTMLPurifier / VarParser.php
blob1d07329a99150e97cd865b210291787be5a58ec9
1 <?php
3 /**
4 * Parses string representations into their corresponding native PHP
5 * variable type.
6 */
7 abstract class HTMLPurifier_VarParser
10 /**
11 * Lookup table of allowed types.
13 static public $types = array(
14 'string' => true,
15 'istring' => true,
16 'text' => true,
17 'itext' => true,
18 'int' => true,
19 'float' => true,
20 'bool' => true,
21 'lookup' => true,
22 'list' => true,
23 'hash' => true,
24 'mixed' => true
27 /**
28 * Validate a variable according to type. Throws
29 * HTMLPurifier_VarParserException if invalid.
30 * It may return NULL as a valid type if $allow_null is true.
32 * @param $var Variable to validate
33 * @param $type Type of variable, see HTMLPurifier_VarParser->types
34 * @param $allow_null Whether or not to permit null as a value
35 * @return Validated and type-coerced variable
37 abstract public function parse($var, $type, $allow_null = false);