XMLParser
in package
uses
DeprecationLogger
Deals with parsing the XML.
Tags
Table of Contents
Constants
- ACCEPT_FAULT = 8
- ACCEPT_REQUEST = 1
- ACCEPT_RESPONSE = 2
- ACCEPT_VALUE = 4
- RETURN_EPIVALS = 'epivals'
- RETURN_PHP = 'phpvals'
- RETURN_XMLRPCVALS = 'xmlrpcvals'
Properties
- $accept : int
- $xmlrpc_valid_parents : array<string|int, mixed>
- $_xh : array<string|int, mixed>
- $current_parsing_options : array<string|int, mixed>
- $maxChunkLength : int
- $maxLogValueLength : int
- $parsing_options : array<string|int, mixed>
- $xmlrpc_valid_parents : array<string|int, array<string|int, mixed>>
Methods
- __construct() : mixed
- __get() : mixed
- __isset() : mixed
- __set() : mixed
- __unset() : mixed
- guessEncoding() : string
- xml charset encoding guessing helper function.
- hasEncoding() : bool
- Helper function: checks if an xml chunk has a charset declaration (BOM or in the xml declaration).
- parse() : array<string|int, mixed>
- Parses an xml-rpc xml string. Results of the parsing are found in $this->['_xh'].
- xmlrpc_se_any() : void
- xml parser handler function for opening element tags.
- handleParsingError() : bool
- logDeprecation() : mixed
- logDeprecationUnlessCalledBy() : void
- truncateValueForLog() : string
- Truncates unsafe data
Constants
ACCEPT_FAULT
public
mixed
ACCEPT_FAULT
= 8
ACCEPT_REQUEST
public
mixed
ACCEPT_REQUEST
= 1
ACCEPT_RESPONSE
public
mixed
ACCEPT_RESPONSE
= 2
ACCEPT_VALUE
public
mixed
ACCEPT_VALUE
= 4
RETURN_EPIVALS
public
mixed
RETURN_EPIVALS
= 'epivals'
RETURN_PHP
public
mixed
RETURN_PHP
= 'phpvals'
RETURN_XMLRPCVALS
public
mixed
RETURN_XMLRPCVALS
= 'xmlrpcvals'
Properties
$accept
public
int
$accept
deprecated - (protected) access left in purely for BC
$xmlrpc_valid_parents
public
array<string|int, mixed>
$xmlrpc_valid_parents
deprecated - public access left in purely for BC
$_xh
protected
array<string|int, mixed>
$_xh
= 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
protected
array<string|int, mixed>
$current_parsing_options
= 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
protected
int
$maxChunkLength
= 4194304
4 MB by default. Any value below 10MB should be good
$maxLogValueLength
protected
int
$maxLogValueLength
= 100
The max length beyond which data will get truncated in error messages
$parsing_options
protected
array<string|int, mixed>
$parsing_options
= array()
$xmlrpc_valid_parents
protected
array<string|int, array<string|int, mixed>>
$xmlrpc_valid_parents
= 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'),
// only used when extension activated
'EX:NIL' => array('VALUE'),
)
Methods
__construct()
public
__construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
-
integer 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)
__get()
public
& __get(mixed $name) : mixed
Parameters
- $name : mixed
__isset()
public
__isset(mixed $name) : mixed
Parameters
- $name : mixed
__set()
public
__set(mixed $name, mixed $value) : mixed
Parameters
- $name : mixed
- $value : mixed
__unset()
public
__unset(mixed $name) : mixed
Parameters
- $name : mixed
guessEncoding()
xml charset encoding guessing helper function.
public
static guessEncoding([string $httpHeader = '' ][, string $xmlChunk = '' ][, string $encodingPrefs = null ]) : string
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:
- http headers
- BOM
- XML declaration
- guesses using mb_detect_encoding()
Parameters
- $httpHeader : string = ''
-
the http Content-type header
- $xmlChunk : string = ''
-
xml content buffer
- $encodingPrefs : string = null
-
comma 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
Tags
Return values
string —the 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
hasEncoding()
Helper function: checks if an xml chunk has a charset declaration (BOM or in the xml declaration).
public
static hasEncoding(string $xmlChunk) : bool
Parameters
- $xmlChunk : string
Tags
Return values
boolparse()
Parses an xml-rpc xml string. Results of the parsing are found in $this->['_xh'].
public
parse(string $data[, string $returnType = self::RETURN_XMLRPCVALS ][, int $accept = 3 ][, array<string|int, mixed> $options = array() ]) : array<string|int, mixed>
Logs to the error log any issues which do not cause the parsing to fail.
Parameters
- $data : string
- $returnType : string = self::RETURN_XMLRPCVALS
-
self::RETURN_XMLRPCVALS, self::RETURN_PHP, self::RETURN_EPIVALS
- $accept : int = 3
-
a bit-combination of self::ACCEPT_REQUEST, self::ACCEPT_RESPONSE, self::ACCEPT_VALUE
- $options : array<string|int, mixed> = array()
-
integer-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
Tags
Return values
array<string|int, mixed> —see the definition of $this->_xh for the meaning of the results
xmlrpc_se_any()
xml parser handler function for opening element tags.
public
xmlrpc_se_any(resource $parser, mixed $name, mixed $attrs) : void
Used in decoding xml chunks that might represent single xml-rpc values as well as requests, responses.
Parameters
- $parser : resource
- $name : mixed
- $attrs : mixed
handleParsingError()
protected
handleParsingError(string $message[, string $method = '' ]) : bool
Parameters
- $message : string
- $method : string = ''
-
method/file/line info
Return values
bool —false if the caller has to stop parsing
logDeprecation()
protected
logDeprecation(mixed $message) : mixed
Parameters
- $message : mixed
logDeprecationUnlessCalledBy()
protected
logDeprecationUnlessCalledBy(string $expectedCaller) : void
Parameters
- $expectedCaller : string
-
atm only the method name is supported
truncateValueForLog()
Truncates unsafe data
protected
truncateValueForLog(string $data) : string
Parameters
- $data : string