HTMLPurifier 4.4.0
HTMLPurifier_VarParser Class Reference

Parses string representations into their corresponding native PHP variable type. More...

Inheritance diagram for HTMLPurifier_VarParser:
HTMLPurifier_VarParser_Flexible HTMLPurifier_VarParser_Flexible HTMLPurifier_VarParser_Native HTMLPurifier_VarParser_Native

List of all members.

Public Member Functions

 parse ($var, $type, $allow_null=false)
 Validate a variable according to type.
 parse ($var, $type, $allow_null=false)
 Validate a variable according to type.

Static Public Member Functions

static getTypeName ($type)
static getTypeName ($type)

Public Attributes

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

static $types
 Lookup table of allowed types.
static $stringTypes
 Lookup table of types that are string, and can have aliases or allowed value lists.

Protected Member Functions

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

Detailed Description

Parses string representations into their corresponding native PHP variable type.

The base implementation does a simple type-check.

Definition at line 7 of file VarParser.php.


Member Function Documentation

HTMLPurifier_VarParser::error ( msg) [protected]

Throws an exception.

Definition at line 120 of file VarParser.php.

Referenced by errorGeneric(), and parse().

HTMLPurifier_VarParser::error ( msg) [protected]

Throws an exception.

Definition at line 8132 of file HTMLPurifier.standalone.php.

HTMLPurifier_VarParser::errorGeneric ( var,
type 
) [protected]

Generic error for if a type didn't work.

Definition at line 137 of file VarParser.php.

References error(), and getTypeName().

Referenced by parse(), and HTMLPurifier_VarParser_Flexible::parseImplementation().

HTMLPurifier_VarParser::errorGeneric ( var,
type 
) [protected]

Generic error for if a type didn't work.

Definition at line 8149 of file HTMLPurifier.standalone.php.

References error(), and getTypeName().

HTMLPurifier_VarParser::errorInconsistent ( class,
type 
) [protected]

Throws an inconsistency exception.

Note:
This should not ever be called. It would be called if we extend the allowed values of HTMLPurifier_VarParser without updating subclasses.

Definition at line 8142 of file HTMLPurifier.standalone.php.

References getTypeName().

HTMLPurifier_VarParser::errorInconsistent ( class,
type 
) [protected]

Throws an inconsistency exception.

Note:
This should not ever be called. It would be called if we extend the allowed values of HTMLPurifier_VarParser without updating subclasses.

Definition at line 130 of file VarParser.php.

References getTypeName().

Referenced by parse(), and HTMLPurifier_VarParser_Flexible::parseImplementation().

static HTMLPurifier_VarParser::getTypeName ( type) [static]

Definition at line 142 of file VarParser.php.

References $types.

Referenced by errorGeneric(), errorInconsistent(), and HTMLPurifier_Config::set().

static HTMLPurifier_VarParser::getTypeName ( type) [static]

Definition at line 8154 of file HTMLPurifier.standalone.php.

References $types.

HTMLPurifier_VarParser::parse ( var,
type,
allow_null = false 
) [final]

Validate a variable according to type.

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

Parameters:
$varVariable to validate
$typeType of variable, see HTMLPurifier_VarParser->types
$allow_nullWhether or not to permit null as a value
Returns:
Validated and type-coerced variable

Definition at line 61 of file VarParser.php.

References $types, error(), errorGeneric(), errorInconsistent(), and parseImplementation().

HTMLPurifier_VarParser::parse ( var,
type,
allow_null = false 
) [final]

Validate a variable according to type.

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

Parameters:
$varVariable to validate
$typeType of variable, see HTMLPurifier_VarParser->types
$allow_nullWhether or not to permit null as a value
Returns:
Validated and type-coerced variable

Definition at line 8073 of file HTMLPurifier.standalone.php.

References $types, error(), errorGeneric(), errorInconsistent(), and parseImplementation().

HTMLPurifier_VarParser::parseImplementation ( var,
type,
allow_null 
) [protected]

Actually implements the parsing.

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

Reimplemented in HTMLPurifier_VarParser_Flexible, HTMLPurifier_VarParser_Native, HTMLPurifier_VarParser_Flexible, and HTMLPurifier_VarParser_Native.

Definition at line 8125 of file HTMLPurifier.standalone.php.

HTMLPurifier_VarParser::parseImplementation ( var,
type,
allow_null 
) [protected]

Actually implements the parsing.

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

Reimplemented in HTMLPurifier_VarParser_Flexible, HTMLPurifier_VarParser_Native, HTMLPurifier_VarParser_Flexible, and HTMLPurifier_VarParser_Native.

Definition at line 113 of file VarParser.php.

Referenced by parse().


Member Data Documentation

static HTMLPurifier_VarParser::$stringTypes [static]
Initial value:
 array(
        self::STRING    => true,
        self::ISTRING   => true,
        self::TEXT      => true,
        self::ITEXT     => true,
    )

Lookup table of types that are string, and can have aliases or allowed value lists.

Definition at line 44 of file VarParser.php.

Referenced by HTMLPurifier_ConfigSchema_Validator::validateDirective().

static HTMLPurifier_VarParser::$types [static]
Initial value:
 array(
        '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
    )

Lookup table of allowed types.

Mainly for backwards compatibility, but also convenient for transforming string type names to the integer constants.

Definition at line 26 of file VarParser.php.

Referenced by HTMLPurifier_ConfigSchema::add(), getTypeName(), parse(), and HTMLPurifier_ConfigSchema_Validator::validateDirective().

Definition at line 15 of file VarParser.php.

Definition at line 14 of file VarParser.php.

Definition at line 11 of file VarParser.php.

Definition at line 10 of file VarParser.php.


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