Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
PhpXmlRpc\Helper\XMLParser Class Reference

Public Member Functions

 __construct (array $options=array())
 
 parse ($data, $returnType=self::RETURN_XMLRPCVALS, $accept=3, $options=array())
 Parses an xml-rpc xml string.
 
 xmlrpc_cd ($parser, $data)
 xml parser handler function for character data.
 
 xmlrpc_dh ($parser, $data)
 xml parser handler function for 'other stuff', i.e.
 
 xmlrpc_ee ($parser, $name, $rebuildXmlrpcvals=1)
 xml parser handler function for close element tags.
 
 xmlrpc_ee_epi ($parser, $name)
 Used in decoding xml-rpc requests/responses while building xmlrpc-extension Values (plain php for all but base64 and datetime).
 
 xmlrpc_ee_fast ($parser, $name)
 Used in decoding xml-rpc requests/responses without rebuilding xml-rpc Values.
 
 xmlrpc_se ($parser, $name, $attrs, $acceptSingleVals=false)
 xml parser handler function for opening element tags.
 

Static Public Member Functions

static guessEncoding ($httpHeader='', $xmlChunk='', $encodingPrefs=null)
 xml charset encoding guessing helper function.
 

Public Attributes

const ACCEPT_FAULT = 8
 
const ACCEPT_REQUEST = 1
 
const ACCEPT_RESPONSE = 2
 
const ACCEPT_VALUE = 4
 
const RETURN_EPIVALS = 'epivals'
 
const RETURN_PHP = 'phpvals'
 
const RETURN_XMLRPCVALS = 'xmlrpcvals'
 

Protected Attributes

array $_xh
 Used to store state during parsing and to pass parsing results to callers.
 
array $current_parsing_options
 Used keys: accept, target_charset, methodname_callback, plus the ones set here.
 
int int $maxChunkLength = 4194304
 $accept self\ACCEPT_REQUEST | self\ACCEPT_RESPONSE by default
 
int $maxLogValueLength = 100
 The max length beyond which data will get truncated in error messages.
 
array $parsing_options = array()
 $parsing_options
 
array[] $xmlrpc_valid_parents
 

Constructor & Destructor Documentation

◆ __construct()

PhpXmlRpc\Helper\XMLParser::__construct ( array $options = array())
Parameters
array$optionsinteger keys: options passed to the inner xml parser string keys:
  • target_charset (string)
  • methodname_callback (callable)
  • xmlrpc_null_extension (bool)
  • xmlrpc_return_datetimes (bool)
  • xmlrpc_reject_invalid_values (bool)

Member Function Documentation

◆ guessEncoding()

static PhpXmlRpc\Helper\XMLParser::guessEncoding ( $httpHeader = '',
$xmlChunk = '',
$encodingPrefs = null )
static

xml charset encoding guessing helper function.

Tries to determine the charset encoding of an XML chunk received over HTTP. NB: according to the spec (RFC 3023), if text/xml content-type is received over HTTP without a content-type, we SHOULD assume it is strictly US-ASCII. But we try to be more tolerant of non-conforming (legacy?) clients/servers, which will be most probably using UTF-8 anyway... In order of importance checks:

  1. http headers
  2. BOM
  3. XML declaration
  4. guesses using mb_detect_encoding()
Parameters
string$httpHeaderthe http Content-type header
string$xmlChunkxml content buffer
string$encodingPrefscomma separated list of character encodings to be used as default (when mb extension is enabled). This can also be set globally using PhpXmlRpc\$xmlrpc_detectencodings
Return values
stringthe encoding determined. Null if it can't be determined and mbstring is enabled, PhpXmlRpc\$xmlrpc_defencoding if it can't be determined and mbstring is not enabled
Todo

explore usage of mb_http_input(): does it detect http headers + post data? if so, use it instead of hand-detection!!!

feature-creep make it possible to pass in options overriding usage of PhpXmlRpc static variables, to make the method independent of global state

◆ parse()

PhpXmlRpc\Helper\XMLParser::parse ( $data,
$returnType = self::RETURN_XMLRPCVALS,
$accept = 3,
$options = array() )

Parses an xml-rpc xml string.

Results of the parsing are found in $this->['_xh']. Logs to the error log any issues which do not cause the parsing to fail.

Parameters
string$data
string$returnTypeself\RETURN_XMLRPCVALS, self\RETURN_PHP, self\RETURN_EPIVALS
int$accepta bit-combination of self\ACCEPT_REQUEST, self\ACCEPT_RESPONSE, self\ACCEPT_VALUE
array$optionsinteger-key options are passed to the xml parser, string-key options are used independently. These options are added to options received in the constructor. Note that if options xmlrpc_null_extension, xmlrpc_return_datetimes and xmlrpc_reject_invalid_values are not set, the default settings from PhpXmlRpc\PhpXmlRpc are used
Return values
arraysee the definition of $this->_xh for the meaning of the results
Exceptions
Exceptionthis can happen if a callback function is set and it does throw (i.e. we do not catch exceptions)
Todo

refactor? we could 1. return the parsed data structure, and 2. move $returnType and $accept into options

feature-creep make it possible to pass in options overriding usage of PhpXmlRpc\$xmlrpc_XXX_format, so that parsing will be completely independent of global state. Note that it might incur a small perf hit...

◆ xmlrpc_dh()

PhpXmlRpc\Helper\XMLParser::xmlrpc_dh ( $parser,
$data )

xml parser handler function for 'other stuff', i.e.

not char data or element start/end tag. In fact, it only gets called on unknown entities...

Member Data Documentation

◆ $_xh

array PhpXmlRpc\Helper\XMLParser::$_xh
protected
Initial value:
= array(
'ac' => '',
'stack' => array(),
'valuestack' => array(),
'lv' => 0,
'isf' => 0,
'isf_reason' => '',
'value' => null,
'method' => false,
'params' => array(),
'pt' => array(),
'rt' => '',
)

Used to store state during parsing and to pass parsing results to callers.

Quick explanation of components: private: ac - used to accumulate values stack - array with genealogy of xml elements names, used to validate nesting of xml-rpc elements valuestack - array used for parsing arrays and structs lv - used to indicate "looking for a value": implements the logic to allow values with no types to be strings (values: 0=not looking, 1=looking, 3=found) public: isf - used to indicate an xml-rpc response fault (1), invalid xml-rpc fault (2), xml parsing fault (3) isf_reason - used for storing xml-rpc response fault string value - used to store the value in responses method - used to store method name in requests params - used to store parameters in requests pt - used to store the type of each received parameter. Useful if parameters are automatically decoded to php values rt - 'methodcall', 'methodresponse', 'value' or 'fault' (the last one used only in EPI emulation mode)

◆ $current_parsing_options

array PhpXmlRpc\Helper\XMLParser::$current_parsing_options
protected
Initial value:
= array(
'xmlrpc_null_extension' => false,
'xmlrpc_return_datetimes' => false,
'xmlrpc_reject_invalid_values' => false
)

Used keys: accept, target_charset, methodname_callback, plus the ones set here.

We initialize it partially to help keep BC with subclasses which might have reimplemented parse() but not the element handler methods

◆ $maxChunkLength

int int PhpXmlRpc\Helper\XMLParser::$maxChunkLength = 4194304
protected

$accept self\ACCEPT_REQUEST | self\ACCEPT_RESPONSE by default

$maxChunkLength 4 MB by default. Any value below 10MB should be good

◆ $xmlrpc_valid_parents

array [] PhpXmlRpc\Helper\XMLParser::$xmlrpc_valid_parents
protected
Initial value:
= array(
'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),
'BOOLEAN' => array('VALUE'),
'I4' => array('VALUE'),
'I8' => array('VALUE'),
'EX:I8' => array('VALUE'),
'INT' => array('VALUE'),
'STRING' => array('VALUE'),
'DOUBLE' => array('VALUE'),
'DATETIME.ISO8601' => array('VALUE'),
'BASE64' => array('VALUE'),
'MEMBER' => array('STRUCT'),
'NAME' => array('MEMBER'),
'DATA' => array('ARRAY'),
'ARRAY' => array('VALUE'),
'STRUCT' => array('VALUE'),
'PARAM' => array('PARAMS'),
'METHODNAME' => array('METHODCALL'),
'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
'FAULT' => array('METHODRESPONSE'),
'NIL' => array('VALUE'),
'EX:NIL' => array('VALUE'),
)

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