Class HTMLPurifier_VarParser

InheritanceHTMLPurifier_VarParser
SubclassesHTMLPurifier_VarParser_Flexible, HTMLPurifier_VarParser_Native

Parses string representations into their corresponding native PHP variable type. The base implementation does a simple type-check.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$stringTypes Lookup table of types that are string, and can have aliases or allowed value lists. HTMLPurifier_VarParser
$types Lookup table of allowed types. Mainly for backwards compatibility, but also convenient for transforming string type names to the integer constants. HTMLPurifier_VarParser

Public Methods

Hide inherited methods

MethodDescriptionDefined By
getTypeName() HTMLPurifier_VarParser
parse() Validate a variable according to type. HTMLPurifier_VarParser

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
error() Throws an exception. HTMLPurifier_VarParser
errorGeneric() Generic error for if a type didn't work. HTMLPurifier_VarParser
errorInconsistent() Throws an inconsistency exception. HTMLPurifier_VarParser
parseImplementation() Actually implements the parsing. Base implementation does not do anything to $var. Subclasses should overload this! HTMLPurifier_VarParser

Property Details

$stringTypes public static property
public static $stringTypes = [self::STRING => trueself::ISTRING => trueself::TEXT => trueself::ITEXT => true]
$types public static property
public static $types = ['string' => self::STRING'istring' => self::ISTRING'text' => self::TEXT'itext' => self::ITEXT'int' => self::INT'float' => self::FLOAT'bool' => self::BOOL'lookup' => self::LOOKUP'list' => self::ALIST'hash' => self::HASH'mixed' => self::MIXED]

Method Details

error() protected method

Throws an exception.

protected void error ( $msg )
$msg
throws HTMLPurifier_VarParserException
errorGeneric() protected method

Generic error for if a type didn't work.

protected void errorGeneric ( $var, $type )
$var mixed
$type int
errorInconsistent() protected method

Throws an inconsistency exception.

protected void errorInconsistent ( $class, $type )
$class string
$type int
throws HTMLPurifier_Exception
getTypeName() public static method

public static string getTypeName ( $type )
$type int
parse() public method

Validate a variable according to type.

It may return NULL as a valid type if $allow_null is true.

public string parse ( $var, $type, $allow_null false )
$var mixed

Variable to validate

$type int

Type of variable, see HTMLPurifier_VarParser->types

$allow_null bool

Whether or not to permit null as a value

return string

Validated and type-coerced variable

throws HTMLPurifier_VarParserException
parseImplementation() protected method

Actually implements the parsing. Base implementation does not do anything to $var. Subclasses should overload this!

protected string parseImplementation ( $var, $type, $allow_null )
$var mixed
$type int
$allow_null bool