Moodle PHP Documentation 4.1
Moodle 4.1.11 (Build: 20240610) (c8c84b4af18)
PhpXmlRpc\Server Class Reference

Public Member Functions

 __construct ($dispatchMap=null, $serviceNow=true)
 
 add_to_map ($methodName, $function, $sig=null, $doc=false, $sigDoc=false)
 Add a method to the dispatch map.
 
 getCapabilities ()
 
 getCharsetEncoder ()
 
 getDispatchMap ()
 
 getLogger ()
 
 getParser ()
 
 getSystemDispatchMap ()
 
 parseRequest ($data, $reqEncoding='')
 Parse an xml chunk containing an xmlrpc request and execute the corresponding php function registered with the server.
 
 serializeDebug ($charsetEncoding='')
 Return a string with the serialized representation of all debug info.
 
 service ($data=null, $returnPayload=false)
 Execute the xmlrpc request, printing the response.
 
 setCharsetEncoder ($charsetEncoder)
 
 setDebug ($level)
 Set debug level of server.
 

Static Public Member Functions

static _xmlrpcs_errorHandler ($errCode, $errString, $filename=null, $lineNo=null, $context=null)
 Error handler used to track errors that occur during server-side execution of PHP code.
 
static _xmlrpcs_getCapabilities ($server, $req=null)
 
static _xmlrpcs_listMethods ($server, $req=null)
 
static _xmlrpcs_methodHelp ($server, $req)
 
static _xmlrpcs_methodSignature ($server, $req)
 
static _xmlrpcs_multicall ($server, $req)
 
static _xmlrpcs_multicall_do_call ($server, $call)
 
static _xmlrpcs_multicall_do_call_phpvals ($server, $call)
 
static _xmlrpcs_multicall_error ($err)
 
static error_occurred ($msg)
 Add a string to the debug info that will be later serialized by the server as part of the response message (base64 encoded, only when debug level >= 2)
 
static setLogger ($logger)
 
static setParser ($parser)
 
static xmlrpc_debugmsg ($msg)
 Add a string to the debug info that can be later serialized by the server as part of the response message.
 

Public Attributes

 $accepted_charset_encodings = array()
 List of charset encodings natively accepted for requests.
 
 $accepted_compression = array()
 List of http compression methods accepted by the server for requests.
 
 $allow_system_funcs = true
 Shall we serve calls to system.* methods?
 
 $compress_response = false
 When set to true, it will enable HTTP compression of the response, in case the client has declared its support for compression in the request.
 
 $debug = 1
 Controls whether the server is going to echo debugging messages back to the client as comments in response body.
 
 $exception_handling = 0
 Controls behaviour of server when the invoked user function throws an exception: 0 = catch it and return an 'internal error' xmlrpc response (default) 1 = catch it and return an xmlrpc response with the error corresponding to the exception 2 = allow the exception to float to the upper layers.
 
 $functions_parameters_type = 'xmlrpcvals'
 Defines how functions in dmap will be invoked: either using an xmlrpc request object or plain php values.
 
 $phpvals_encoding_options = array('auto_dates')
 Option used for fine-tuning the encoding the php values returned from functions registered in the dispatch map when the functions_parameters_types member is set to 'phpvals'.
 
 $response_charset_encoding = ''
 Charset encoding to be used for response.
 
 $user_data = null
 Extra data passed at runtime to method handling functions.
 

Protected Member Functions

 debugmsg ($string)
 Add a string to the 'internal debug message' (separate from 'user debug message').
 
 execute ($req, $params=null, $paramTypes=null)
 Execute a method invoked by the client, checking parameters used.
 
 isSyscall ($methName)
 
 parseRequestHeaders (&$data, &$reqEncoding, &$respEncoding, &$respCompression)
 Parse http headers received along with xmlrpc request.
 
 verifySignature ($in, $sigs)
 Verify type and number of parameters received against a list of known signatures.
 
 xml_header ($charsetEncoding='')
 

Protected Attributes

 $debug_info = ''
 Storage for internal debug info.
 
array[] $dmap = array()
 Array defining php functions exposed as xmlrpc methods by this server.
 

Static Protected Attributes

static $_xmlrpc_debuginfo = ''
 
static $_xmlrpcs_occurred_errors = ''
 
static $_xmlrpcs_prev_ehandler = ''
 
static $charsetEncoder
 
static $logger
 
static $parser
 

Constructor & Destructor Documentation

◆ __construct()

PhpXmlRpc\Server::__construct ( $dispatchMap = null,
$serviceNow = true )
Parameters
array[]$dispatchMapthe dispatch map with definition of exposed services Array keys are the names of the method names. Each array value is an array with the following members:
  • function (callable)
  • docstring (optional)
  • signature (array, optional)
  • signature_docs (array, optional)
  • parameters_type (string, optional)
boolean$serviceNowset to false to prevent the server from running upon construction

Member Function Documentation

◆ _xmlrpcs_errorHandler()

static PhpXmlRpc\Server::_xmlrpcs_errorHandler ( $errCode,
$errString,
$filename = null,
$lineNo = null,
$context = null )
static

Error handler used to track errors that occur during server-side execution of PHP code.

This allows to report back to the client whether an internal error has occurred or not using an xmlrpc response object, instead of letting the client deal with the html junk that a PHP execution error on the server generally entails.

NB: in fact a user defined error handler can only handle WARNING, NOTICE and USER_* errors.

◆ _xmlrpcs_getCapabilities()

static PhpXmlRpc\Server::_xmlrpcs_getCapabilities ( $server,
$req = null )
static
Parameters
Server$server
Request$req
Return values
Response

◆ _xmlrpcs_listMethods()

static PhpXmlRpc\Server::_xmlrpcs_listMethods ( $server,
$req = null )
static
Parameters
Server$server
Request$reqif called in plain php values mode, second param is missing
Return values
Response

◆ _xmlrpcs_methodHelp()

static PhpXmlRpc\Server::_xmlrpcs_methodHelp ( $server,
$req )
static
Parameters
Server$server
Request$req
Return values
Response

◆ _xmlrpcs_methodSignature()

static PhpXmlRpc\Server::_xmlrpcs_methodSignature ( $server,
$req )
static
Parameters
Server$server
Request$req
Return values
Response

◆ _xmlrpcs_multicall()

static PhpXmlRpc\Server::_xmlrpcs_multicall ( $server,
$req )
static
Parameters
Server$server
Request | array$req
Return values
Response

◆ _xmlrpcs_multicall_do_call()

static PhpXmlRpc\Server::_xmlrpcs_multicall_do_call ( $server,
$call )
static
Parameters
Server$server
Value$call
Return values
Value

◆ _xmlrpcs_multicall_do_call_phpvals()

static PhpXmlRpc\Server::_xmlrpcs_multicall_do_call_phpvals ( $server,
$call )
static
Parameters
Server$server
Value$call
Return values
Value

◆ add_to_map()

PhpXmlRpc\Server::add_to_map ( $methodName,
$function,
$sig = null,
$doc = false,
$sigDoc = false )

Add a method to the dispatch map.

Parameters
string$methodNamethe name with which the method will be made available
callable$functionthe php function that will get invoked
array[]$sigthe array of valid method signatures. Each element is one signature: an array of strings with at least one element First element = type of returned value. Elements 2..N = types of parameters 1..N
string$docmethod documentation
array[]$sigDocthe array of valid method signatures docs, following the format of $sig but with descriptions instead of types (one string for return type, one per param)
Todo

raise a warning if the user tries to register a 'system.' method

allow setting parameters_type

◆ debugmsg()

PhpXmlRpc\Server::debugmsg ( $string)
protected

Add a string to the 'internal debug message' (separate from 'user debug message').

Parameters
string$string

◆ error_occurred()

static PhpXmlRpc\Server::error_occurred ( $msg)
static

Add a string to the debug info that will be later serialized by the server as part of the response message (base64 encoded, only when debug level >= 2)

character set.

Parameters
string$msg

◆ execute()

PhpXmlRpc\Server::execute ( $req,
$params = null,
$paramTypes = null )
protected

Execute a method invoked by the client, checking parameters used.

Parameters
Request | string$reqeither a Request obj or a method name
mixed[]$paramsarray with method parameters as php types (only if m is method name)
string[]$paramTypesarray with xmlrpc types of method parameters (only if m is method name)
Return values
Response
Exceptions
Exceptionin case the executed method does throw an exception (and depending on server configuration)

◆ getCapabilities()

PhpXmlRpc\Server::getCapabilities ( )
Return values
array[]

◆ getDispatchMap()

PhpXmlRpc\Server::getDispatchMap ( )
Return values
array[]

◆ getSystemDispatchMap()

PhpXmlRpc\Server::getSystemDispatchMap ( )
Return values
array[]

◆ isSyscall()

PhpXmlRpc\Server::isSyscall ( $methName)
protected
Parameters
string$methName
Return values
bool

◆ parseRequest()

PhpXmlRpc\Server::parseRequest ( $data,
$reqEncoding = '' )

Parse an xml chunk containing an xmlrpc request and execute the corresponding php function registered with the server.

Parameters
string$datathe xml request
string$reqEncoding(optional) the charset encoding of the xml request
Return values
Response
Exceptions
Exceptionin case the executed method does throw an exception (and depending on server configuration)

◆ parseRequestHeaders()

PhpXmlRpc\Server::parseRequestHeaders ( & $data,
& $reqEncoding,
& $respEncoding,
& $respCompression )
protected

Parse http headers received along with xmlrpc request.

If needed, inflate request.

Return values
Response|nullnull on success or an error Response

◆ serializeDebug()

PhpXmlRpc\Server::serializeDebug ( $charsetEncoding = '')

Return a string with the serialized representation of all debug info.

Parameters
string$charsetEncodingthe target charset encoding for the serialization
Return values
stringan XML comment (or two)

◆ service()

PhpXmlRpc\Server::service ( $data = null,
$returnPayload = false )

Execute the xmlrpc request, printing the response.

Parameters
string$datathe request body. If null, the http POST request will be examined
bool$returnPayloadWhen true, return the response but do not echo it or any http header
Return values
Response|stringthe response object (usually not used by caller...) or its xml serialization
Exceptions
Exceptionin case the executed method does throw an exception (and depending on server configuration)

◆ setDebug()

PhpXmlRpc\Server::setDebug ( $level)

Set debug level of server.

Parameters
integer$leveldebug lvl: determines info added to xmlrpc responses (as xml comments) 0 = no debug info, 1 = msgs set from user with debugmsg(), 2 = add complete xmlrpc request (headers and body), 3 = add also all processing warnings happened during method processing (NB: this involves setting a custom error handler, and might interfere with the standard processing of the php function exposed as method. In particular, triggering an USER_ERROR level error will not halt script execution anymore, but just end up logged in the xmlrpc response) Note that info added at level 2 and 3 will be base64 encoded

◆ verifySignature()

PhpXmlRpc\Server::verifySignature ( $in,
$sigs )
protected

Verify type and number of parameters received against a list of known signatures.

Parameters
array | Request$inarray of either xmlrpc value objects or xmlrpc type definitions
array$sigsarray of known signatures to match against
Return values
arrayint, string

◆ xml_header()

PhpXmlRpc\Server::xml_header ( $charsetEncoding = '')
protected
Parameters
string$charsetEncoding
Return values
string

◆ xmlrpc_debugmsg()

static PhpXmlRpc\Server::xmlrpc_debugmsg ( $msg)
static

Add a string to the debug info that can be later serialized by the server as part of the response message.

Note that for best compatibility, the debug string should be encoded using the PhpXmlRpc\$xmlrpc_internalencoding character set.

Parameters
string$msg

Member Data Documentation

◆ $accepted_charset_encodings

PhpXmlRpc\Server::$accepted_charset_encodings = array()

List of charset encodings natively accepted for requests.

Set at constructor time. UNUSED so far...

◆ $accepted_compression

PhpXmlRpc\Server::$accepted_compression = array()

List of http compression methods accepted by the server for requests.

Set at constructor time. NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib

◆ $compress_response

PhpXmlRpc\Server::$compress_response = false

When set to true, it will enable HTTP compression of the response, in case the client has declared its support for compression in the request.

Set at constructor time.

◆ $debug

PhpXmlRpc\Server::$debug = 1

Controls whether the server is going to echo debugging messages back to the client as comments in response body.

Valid values: 0,1,2,3

◆ $dmap

array [] PhpXmlRpc\Server::$dmap = array()
protected

Array defining php functions exposed as xmlrpc methods by this server.

$dmap

◆ $functions_parameters_type

PhpXmlRpc\Server::$functions_parameters_type = 'xmlrpcvals'

Defines how functions in dmap will be invoked: either using an xmlrpc request object or plain php values.

Valid strings are 'xmlrpcvals', 'phpvals' or 'epivals'

Todo
create class constants for these

◆ $phpvals_encoding_options

PhpXmlRpc\Server::$phpvals_encoding_options = array('auto_dates')

Option used for fine-tuning the encoding the php values returned from functions registered in the dispatch map when the functions_parameters_types member is set to 'phpvals'.

See also
Encoder\encode for a list of values

◆ $response_charset_encoding

PhpXmlRpc\Server::$response_charset_encoding = ''

Charset encoding to be used for response.

NB: if we can, we will convert the generated response from internal_encoding to the intended one. Can be: a supported xml encoding (only UTF-8 and ISO-8859-1 at present, unless mbstring is enabled), null (leave unspecified in response, convert output stream to US_ASCII), 'default' (use xmlrpc library default as specified in xmlrpc.inc, convert output stream if needed), or 'auto' (use client-specified charset encoding or same as request if request headers do not specify it (unless request is US-ASCII: then use library default anyway). NB: pretty dangerous if you accept every charset and do not have mbstring enabled)

◆ $user_data

PhpXmlRpc\Server::$user_data = null

Extra data passed at runtime to method handling functions.

Used only by EPI layer


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