Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 382 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Encoder:: (7 methods):
  getLogger()
  setLogger()
  getParser()
  setParser()
  decode()
  encode()
  decodeXml()


Class: Encoder  - X-Ref

A helper class to easily convert between Value objects and php native values

getLogger()   X-Ref
No description

setLogger($logger)   X-Ref
No description

getParser()   X-Ref
No description

setParser($parser)   X-Ref
No description

decode($xmlrpcVal, $options = array()   X-Ref
Takes an xmlrpc value in object format and translates it into native PHP types.

Works with xmlrpc requests objects as input, too.

Given proper options parameter, can rebuild generic php object instances (provided those have been encoded to
xmlrpc format using a corresponding option in php_xmlrpc_encode())
PLEASE NOTE that rebuilding php objects involves calling their constructor function.
This means that the remote communication end can decide which php code will get executed on your server, leaving
the door possibly open to 'php-injection' style of attacks (provided you have some classes defined on your server
that might wreak havoc if instances are built outside an appropriate context).
Make sure you trust the remote server/client before enabling this!

param: Value|Request $xmlrpcVal
param: array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php
author: Dan Libby (dan@libby.com)
return: mixed

encode($phpVal, $options = array()   X-Ref
Takes native php types and encodes them into xmlrpc PHP object format.
It will not re-encode xmlrpc value objects.

Feature creep -- could support more types via optional type argument
(string => datetime support has been added, ??? => base64 not yet)

If given a proper options parameter, php object instances will be encoded into 'special' xmlrpc values, that can
later be decoded into php objects by calling php_xmlrpc_decode() with a corresponding option

param: mixed $phpVal the value to be converted into an xmlrpc value object
param: array $options can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'
author: Dan Libby (dan@libby.com)
return: Value

decodeXml($xmlVal, $options = array()   X-Ref
Convert the xml representation of a method response, method request or single
xmlrpc value into the appropriate object (a.k.a. deserialize).

param: string $xmlVal
param: array $options
return: Value|Request|Response|false false on error, or an instance of either Value, Request or Response