NXS_XMLRPC_IntrospectionServer

NXS_XMLRPC_IntrospectionServer.

Defined (1)

The class is defined in the following location(s).

/inc-cl/apis/xmlrpc-client.php  
  1. class NXS_XMLRPC_IntrospectionServer extends NXS_XMLRPC_Server 
  2. var $signatures; 
  3. var $help; 
  4.  
  5. function NXS_XMLRPC_IntrospectionServer() 
  6. $this->setCallbacks(); 
  7. $this->setCapabilities(); 
  8. $this->capabilities['introspection'] = array( 
  9. 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',  
  10. 'specVersion' => 1 
  11. ); 
  12. $this->addCallback( 
  13. 'system.methodSignature',  
  14. 'this:methodSignature',  
  15. array('array', 'string'),  
  16. 'Returns an array describing the return type and required parameters of a method' 
  17. ); 
  18. $this->addCallback( 
  19. 'system.getCapabilities',  
  20. 'this:getCapabilities',  
  21. array('struct'),  
  22. 'Returns a struct describing the XML-RPC specifications supported by this server' 
  23. ); 
  24. $this->addCallback( 
  25. 'system.listMethods',  
  26. 'this:listMethods',  
  27. array('array'),  
  28. 'Returns an array of available methods on this server' 
  29. ); 
  30. $this->addCallback( 
  31. 'system.methodHelp',  
  32. 'this:methodHelp',  
  33. array('string', 'string'),  
  34. 'Returns a documentation string for the specified method' 
  35. ); 
  36.  
  37. function addCallback($method, $callback, $args, $help) 
  38. $this->callbacks[$method] = $callback; 
  39. $this->signatures[$method] = $args; 
  40. $this->help[$method] = $help; 
  41.  
  42. function call($methodname, $args) 
  43. // Make sure it's in an array 
  44. if ($args && !is_array($args)) { 
  45. $args = array($args); 
  46.  
  47. // Over-rides default call method, adds signature check 
  48. if (!$this->hasMethod($methodname)) { 
  49. return new NXS_XMLRPC_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); 
  50. $method = $this->callbacks[$methodname]; 
  51. $signature = $this->signatures[$methodname]; 
  52. $returnType = array_shift($signature); 
  53.  
  54. // Check the number of arguments 
  55. if (count($args) != count($signature)) { 
  56. return new NXS_XMLRPC_Error(-32602, 'server error. wrong number of method parameters'); 
  57.  
  58. // Check the argument types 
  59. $ok = true; 
  60. $argsbackup = $args; 
  61. for ($i = 0, $j = count($args); $i < $j; $i++) { 
  62. $arg = array_shift($args); 
  63. $type = array_shift($signature); 
  64. switch ($type) { 
  65. case 'int': 
  66. case 'i4': 
  67. if (is_array($arg) || !is_int($arg)) { 
  68. $ok = false; 
  69. break; 
  70. case 'base64': 
  71. case 'string': 
  72. if (!is_string($arg)) { 
  73. $ok = false; 
  74. break; 
  75. case 'boolean': 
  76. if ($arg !== false && $arg !== true) { 
  77. $ok = false; 
  78. break; 
  79. case 'float': 
  80. case 'double': 
  81. if (!is_float($arg)) { 
  82. $ok = false; 
  83. break; 
  84. case 'date': 
  85. case 'dateTime.iso8601': 
  86. if (!is_a($arg, 'NXS_XMLRPC_Date')) { 
  87. $ok = false; 
  88. break; 
  89. if (!$ok) { 
  90. return new NXS_XMLRPC_Error(-32602, 'server error. invalid method parameters'); 
  91. // It passed the test - run the "real" method call 
  92. return parent::call($methodname, $argsbackup); 
  93.  
  94. function methodSignature($method) 
  95. if (!$this->hasMethod($method)) { 
  96. return new NXS_XMLRPC_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); 
  97. // We should be returning an array of types 
  98. $types = $this->signatures[$method]; 
  99. $return = array(); 
  100. foreach ($types as $type) { 
  101. switch ($type) { 
  102. case 'string': 
  103. $return[] = 'string'; 
  104. break; 
  105. case 'int': 
  106. case 'i4': 
  107. $return[] = 42; 
  108. break; 
  109. case 'double': 
  110. $return[] = 3.1415; 
  111. break; 
  112. case 'dateTime.iso8601': 
  113. $return[] = new NXS_XMLRPC_Date(time()); 
  114. break; 
  115. case 'boolean': 
  116. $return[] = true; 
  117. break; 
  118. case 'base64': 
  119. $return[] = new NXS_XMLRPC_Base64('base64'); 
  120. break; 
  121. case 'array': 
  122. $return[] = array('array'); 
  123. break; 
  124. case 'struct': 
  125. $return[] = array('struct' => 'struct'); 
  126. break; 
  127. return $return; 
  128.  
  129. function methodHelp($method) 
  130. return $this->help[$method];