Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
HTMLPurifier_VarParser Class Reference
Inheritance diagram for HTMLPurifier_VarParser:
HTMLPurifier_VarParser_Flexible HTMLPurifier_VarParser_Native

Public Member Functions

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

Static Public Member Functions

static getTypeName ($type)
 

Public Attributes

const ALIST = 9
 
const C_BOOL = 7
 
const C_FLOAT = 6
 
const C_INT = 5
 
const C_MIXED = 11
 
const C_STRING = 1
 
const HASH = 10
 
const ISTRING = 2
 
const ITEXT = 4
 
const LOOKUP = 8
 
const TEXT = 3
 

Static Public Attributes

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

Protected Member Functions

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

Member Function Documentation

◆ error()

HTMLPurifier_VarParser::error ( $msg)
protected

Throws an exception.

Exceptions
HTMLPurifier_VarParserException

◆ errorGeneric()

HTMLPurifier_VarParser::errorGeneric ( $var,
$type )
protected

Generic error for if a type didn't work.

Parameters
mixed$var
int$type

◆ errorInconsistent()

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.
Parameters
string$class
int$type
Exceptions
HTMLPurifier_Exception

◆ getTypeName()

static HTMLPurifier_VarParser::getTypeName ( $type)
static
Parameters
int$type
Return values
string

◆ parse()

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

Validate a variable according to type.

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

Parameters
mixed$varVariable to validate
int$typeType of variable, see HTMLPurifier_VarParser->types
bool$allow_nullWhether or not to permit null as a value
Return values
stringValidated and type-coerced variable
Exceptions
HTMLPurifier_VarParserException

◆ parseImplementation()

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

Actually implements the parsing.

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

Parameters
mixed$var
int$type
bool$allow_null
Return values
string

Reimplemented in HTMLPurifier_VarParser_Flexible, and HTMLPurifier_VarParser_Native.

Member Data Documentation

◆ $stringTypes

HTMLPurifier_VarParser::$stringTypes
static
Initial value:
= array(
self::C_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.

◆ $types

HTMLPurifier_VarParser::$types
static
Initial value:
= array(
'string' => self::C_STRING,
'istring' => self::ISTRING,
'text' => self::TEXT,
'itext' => self::ITEXT,
'int' => self::C_INT,
'float' => self::C_FLOAT,
'bool' => self::C_BOOL,
'lookup' => self::LOOKUP,
'list' => self::ALIST,
'hash' => self::HASH,
'mixed' => self::C_MIXED
)

Lookup table of allowed types.

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


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