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]

   1  <?php
   2  
   3  namespace PhpXmlRpc;
   4  
   5  /**
   6   * Manages global configuration for operation of the library.
   7   */
   8  class PhpXmlRpc
   9  {
  10      static public $xmlrpcerr = array(
  11          'unknown_method' => 1,
  12          'invalid_return' => 2,
  13          'incorrect_params' => 3,
  14          'introspect_unknown' => 4,
  15          'http_error' => 5,
  16          'no_data' => 6,
  17          'no_ssl' => 7,
  18          'curl_fail' => 8,
  19          'invalid_request' => 15,
  20          'no_curl' => 16,
  21          'server_error' => 17,
  22          'multicall_error' => 18,
  23          'multicall_notstruct' => 9,
  24          'multicall_nomethod' => 10,
  25          'multicall_notstring' => 11,
  26          'multicall_recursion' => 12,
  27          'multicall_noparams' => 13,
  28          'multicall_notarray' => 14,
  29          'no_http2' => 15,
  30  
  31          'cannot_decompress' => 103,
  32          'decompress_fail' => 104,
  33          'dechunk_fail' => 105,
  34          'server_cannot_decompress' => 106,
  35          'server_decompress_fail' => 107,
  36      );
  37  
  38      static public $xmlrpcstr = array(
  39          'unknown_method' => 'Unknown method',
  40          'invalid_return' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)',
  41          'incorrect_params' => 'Incorrect parameters passed to method',
  42          'introspect_unknown' => "Can't introspect: method unknown",
  43          'http_error' => "Didn't receive 200 OK from remote server",
  44          'no_data' => 'No data received from server',
  45          'no_ssl' => 'No SSL support compiled in',
  46          'curl_fail' => 'CURL error',
  47          'invalid_request' => 'Invalid request payload',
  48          'no_curl' => 'No CURL support compiled in',
  49          'server_error' => 'Internal server error',
  50          'multicall_error' => 'Received from server invalid multicall response',
  51          'multicall_notstruct' => 'system.multicall expected struct',
  52          'multicall_nomethod' => 'Missing methodName',
  53          'multicall_notstring' => 'methodName is not a string',
  54          'multicall_recursion' => 'Recursive system.multicall forbidden',
  55          'multicall_noparams' => 'Missing params',
  56          'multicall_notarray' => 'params is not an array',
  57          'no_http2' => 'No HTTP/2 support compiled in',
  58  
  59          'cannot_decompress' => 'Received from server compressed HTTP and cannot decompress',
  60          'decompress_fail' => 'Received from server invalid compressed HTTP',
  61          'dechunk_fail' => 'Received from server invalid chunked HTTP',
  62          'server_cannot_decompress' => 'Received from client compressed HTTP request and cannot decompress',
  63          'server_decompress_fail' => 'Received from client invalid compressed HTTP request',
  64      );
  65  
  66      // The charset encoding used by the server for received requests and by the client for received responses when
  67      // received charset cannot be determined and mbstring extension is not enabled
  68      public static $xmlrpc_defencoding = "UTF-8";
  69  
  70      // The list of encodings used by the server for requests and by the client for responses to detect the charset of
  71      // the received payload when
  72      // - the charset cannot be determined by looking at http headers, xml declaration or BOM
  73      // - mbstring extension is enabled
  74      public static $xmlrpc_detectencodings = array();
  75  
  76      // The encoding used internally by PHP.
  77      // String values received as xml will be converted to this, and php strings will be converted to xml as if
  78      // having been coded with this.
  79      // Valid also when defining names of xmlrpc methods
  80      public static $xmlrpc_internalencoding = "UTF-8";
  81  
  82      public static $xmlrpcName = "XML-RPC for PHP";
  83      public static $xmlrpcVersion = "4.8.1";
  84  
  85      // let user errors start at 800
  86      public static $xmlrpcerruser = 800;
  87      // let XML parse errors start at 100
  88      public static $xmlrpcerrxml = 100;
  89  
  90      // set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
  91      public static $xmlrpc_null_extension = false;
  92  
  93      // set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
  94      public static $xmlrpc_null_apache_encoding = false;
  95  
  96      public static $xmlrpc_null_apache_encoding_ns = "http://ws.apache.org/xmlrpc/namespaces/extensions";
  97  
  98      // number of decimal digits used to serialize Double values
  99      public static $xmlpc_double_precision = 128;
 100  
 101      /**
 102       * A function to be used for compatibility with legacy code: it creates all global variables which used to be declared,
 103       * such as library version etc...
 104       */
 105      public static function exportGlobals()
 106      {
 107          $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
 108          foreach ($reflection->getStaticProperties() as $name => $value) {
 109              $GLOBALS[$name] = $value;
 110          }
 111  
 112          // NB: all the variables exported into the global namespace below here do NOT guarantee 100% compatibility,
 113          // as they are NOT reimported back during calls to importGlobals()
 114  
 115          $reflection = new \ReflectionClass('PhpXmlRpc\Value');
 116          foreach ($reflection->getStaticProperties() as $name => $value) {
 117              $GLOBALS[$name] = $value;
 118          }
 119  
 120          $parser = new Helper\XMLParser();
 121          $reflection = new \ReflectionClass('PhpXmlRpc\Helper\XMLParser');
 122          foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $name => $value) {
 123              if (in_array($value->getName(), array('xmlrpc_valid_parents')))
 124              {
 125                  $GLOBALS[$value->getName()] = $value->getValue($parser);
 126              }
 127          }
 128  
 129          $charset = Helper\Charset::instance();
 130          $GLOBALS['xml_iso88591_Entities'] = $charset->getEntities('iso88591');
 131      }
 132  
 133      /**
 134       * A function to be used for compatibility with legacy code: it gets the values of all global variables which used
 135       * to be declared, such as library version etc... and sets them to php classes.
 136       * It should be used by code which changed the values of those global variables to alter the working of the library.
 137       * Example code:
 138       * 1. include xmlrpc.inc
 139       * 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
 140       * 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals();
 141       * 4. run your own code.
 142       */
 143      public static function importGlobals()
 144      {
 145          $reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc');
 146          $staticProperties = $reflection->getStaticProperties();
 147          foreach ($staticProperties as $name => $value) {
 148              if (isset($GLOBALS[$name])) {
 149                  self::$$name = $GLOBALS[$name];
 150              }
 151          }
 152      }
 153  }