Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
Util

Functions

 __construct ($text, $charset=null)
 Constructor.
 
 __get ($varname)
 Returns the value of a given form variable.
 
 __isset ($varname)
 isset() implementation.
 
 __set ($varname, $value)
 Sets the value of a given form variable.
 
 __unset ($varname)
 Deletes a given form variable.
 
static _fallbackToAscii ($str)
 Transliterate using a built-in ASCII mapping.
 
 _getExists ($array, $varname, &$value)
 Fetch the requested variable ($varname) into $value, and return whether or not the variable was set in $array.
 
static _iconvToAscii ($str)
 Transliterate using the iconv extension.
 
static _intlToAscii ($str)
 Transliterate using the Transliterator package.
 
 _loadHTML ($html)
 Loads the HTML data.
 
 add ($varname, $value)
 Set $varname to $value ONLY if it's not already present.
 
 count ()
 
 current ()
 
 exists ($varname)
 Alias of isset().
 
 filter ($varname)
 Filters a form value so that it can be used in HTML output.
 
 get ($varname, $default=null)
 Returns the value of a given form variable.
 
 getBody ()
 Returns the BODY element, or creates one if it doesn't exist.
 
 getCharset ()
 Get the charset of the DOM data.
 
static getDefaultVariables ($sanitize=false)
 Returns a Horde_Variables object populated with the form input.
 
 getExists ($varname, &$exists)
 Given a variable name, returns the value and sets a variable indicating whether the value exists in the form data.
 
 getHead ()
 Returns the HEAD element, or creates one if it doesn't exist.
 
 getIterator ()
 
 key ()
 
 merge ($vars)
 Merges a list of variables into the current form variable list.
 
 next ()
 
 offsetExists ($field)
 Implements isset() for ArrayAccess interface.
 
 offsetGet ($field)
 Implements getter for ArrayAccess interface.
 
 offsetSet ($field, $value)
 Implements setter for ArrayAccess interface.
 
 offsetUnset ($field)
 Implements unset() for ArrayAccess interface.
 
 remove ($varname)
 Deletes a given form variable.
 
 returnBody ()
 Returns the body text in the original charset.
 
 returnHtml (array $opts=array())
 Returns the full HTML text in the original charset.
 
 rewind ()
 
 sanitize ()
 Sanitize the form input.
 
 set ($varname, $value)
 Sets the value of a given form variable.
 
static toAscii ($str)
 Transliterates an UTF-8 string to ASCII, replacing non-English characters to their English equivalents.
 
 valid ()
 

Variables

array $_iterator = null
 Iterator status.
 
string $_origCharset
 Original charset of data.
 
boolean $_sanitized = false
 Has the input been sanitized?
 
static Transliterator $_transliterator
 Transliterator instance.
 
array $_vars
 Array of form variables.
 
string $_xmlencoding = ''
 Encoding tag added to beginning of output.
 
*See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see Countable
 
*See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see http
 
*See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see http
 
*See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see http
 
*See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see IteratorAggregate
 

Detailed Description

Function Documentation

◆ __construct()

__construct ( $vars = array(),
$sanitize = null )

Constructor.

Parameters
string$textThe text of the HTML document.
string$charsetThe charset of the HTML document.
Exceptions
Exception
Parameters
array$varsThe list of form variables (if null, defaults to PHP's $_REQUEST value). If '_formvars' exists, it must be a JSON encoded array that contains the list of allowed form variables.
string$sanitizeSanitize the input variables?

◆ __get()

__get ( $varname)

Returns the value of a given form variable.

Parameters
string$varnameThe form variable name.
Return values
mixedThe form variable, or null if it doesn't exist.

◆ __isset()

__isset ( $varname)

isset() implementation.

Parameters
string$varnameThe form variable name.
Return values
booleanDoes $varname form variable exist?

◆ __set()

__set ( $varname,
$value )

Sets the value of a given form variable.

Parameters
string$varnameThe form variable name.
mixed$valueThe value to set.

◆ __unset()

__unset ( $varname)

Deletes a given form variable.

Parameters
string$varnameThe form variable name.

◆ _fallbackToAscii()

static _fallbackToAscii ( $str)
staticprotected

Transliterate using a built-in ASCII mapping.

Parameters
string$strInput string (UTF-8).
Return values
stringTransliterated string (UTF-8).

◆ _getExists()

_getExists ( $array,
$varname,
& $value )
protected

Fetch the requested variable ($varname) into $value, and return whether or not the variable was set in $array.

Parameters
array$arrayThe array to search in (usually either $this->_vars or $this->_expected).
string$varnameThe name of the variable to look for.
mixed&$value$varname's value gets assigned to this variable.
Return values
booleanWhether or not the variable was set (or, if we've checked $this->_expected, should have been set).

◆ _iconvToAscii()

static _iconvToAscii ( $str)
staticprotected

Transliterate using the iconv extension.

Parameters
string$strInput string (UTF-8).
Return values
mixedTransliterated string (UTF-8), or false on error.

◆ _intlToAscii()

static _intlToAscii ( $str)
staticprotected

Transliterate using the Transliterator package.

Parameters
string$strInput string (UTF-8).
Return values
mixedTransliterated string (UTF-8), or false on error.

◆ _loadHTML()

_loadHTML ( $html)
protected

Loads the HTML data.

Parameters
string$htmlHTML data.

◆ add()

add ( $varname,
$value )

Set $varname to $value ONLY if it's not already present.

Parameters
string$varnameThe form variable name.
mixed$valueThe value to set.
Return values
booleanTrue if the value was altered.

◆ exists()

exists ( $varname)

Alias of isset().

See also
__isset()

◆ filter()

filter ( $varname)

Filters a form value so that it can be used in HTML output.

Parameters
string$varnameThe form variable name.
Return values
mixedThe filtered variable, or null if it doesn't exist.

◆ get()

get ( $varname,
$default = null )

Returns the value of a given form variable.

Parameters
string$varnameThe form variable name.
string$defaultThe default form variable value.
Return values
mixedThe form variable, or $default if it doesn't exist.

◆ getBody()

getBody ( )

Returns the BODY element, or creates one if it doesn't exist.

Since
2.2.0
Return values
DOMElementBODY element.

◆ getCharset()

getCharset ( )

Get the charset of the DOM data.

Since
2.1.0
Return values
stringCharset of DOM data.

◆ getDefaultVariables()

static getDefaultVariables ( $sanitize = false)
static

Returns a Horde_Variables object populated with the form input.

Parameters
string$sanitizeSanitize the input variables?
Return values
Horde_VariablesVariables object.

◆ getExists()

getExists ( $varname,
& $exists )

Given a variable name, returns the value and sets a variable indicating whether the value exists in the form data.

Parameters
string$varnameThe form variable name.
boolean&$existsReference to variable that will indicate whether $varname existed in form data.
Return values
mixedThe form variable, or null if it doesn't exist.

◆ getHead()

getHead ( )

Returns the HEAD element, or creates one if it doesn't exist.

Return values
DOMElementHEAD element.

◆ merge()

merge ( $vars)

Merges a list of variables into the current form variable list.

Parameters
array$varsForm variables.

◆ offsetExists()

offsetExists ( $field)

Implements isset() for ArrayAccess interface.

See also
__isset()

◆ offsetGet()

offsetGet ( $field)

Implements getter for ArrayAccess interface.

See also
__get()

◆ offsetSet()

offsetSet ( $field,
$value )

Implements setter for ArrayAccess interface.

See also
__set()

◆ offsetUnset()

offsetUnset ( $field)

Implements unset() for ArrayAccess interface.

See also
__unset()

◆ remove()

remove ( $varname)

Deletes a given form variable.

See also
__unset()

◆ returnBody()

returnBody ( )

Returns the body text in the original charset.

Return values
stringHTML text.

◆ returnHtml()

returnHtml ( array $opts = array())

Returns the full HTML text in the original charset.

Parameters
array$optsAdditional options: (since 2.1.0)
  • charset: (string) Return using this charset. If set but empty, will return as currently stored in the DOM object.
  • metacharset: (boolean) If true, will add a META tag containing the charset information.
Return values
stringHTML text.

◆ set()

set ( $varname,
$value )

Sets the value of a given form variable.

See also
__set()

◆ toAscii()

static toAscii ( $str)
static

Transliterates an UTF-8 string to ASCII, replacing non-English characters to their English equivalents.

Note: there is no guarantee that the output string will be ASCII-only, since any non-ASCII character not in the transliteration list will be ignored.

Parameters
string$strInput string (UTF-8).
Return values
stringTransliterated string (UTF-8).

Variable Documentation

◆ IteratorAggregate

*See the enclosed file LICENSE for license information (LGPL). If you *did not receive this file see IteratorAggregate
Initial value:
{
protected array $_expected = array()