IXR_IntrospectionServer

IXR_IntrospectionServer.

Defined (1)

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

/bp-forums/bbpress/bb-includes/backpress/class.ixr.php  
  1. class IXR_IntrospectionServer extends IXR_Server 
  2. var $signatures; 
  3. var $help; 
  4.  
  5. function __construct() 
  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 IXR_IntrospectionServer() 
  38. $this->__construct(); 
  39.  
  40. function addCallback($method, $callback, $args, $help) 
  41. $this->callbacks[$method] = $callback; 
  42. $this->signatures[$method] = $args; 
  43. $this->help[$method] = $help; 
  44.  
  45. function call($methodname, $args) 
  46. // Make sure it's in an array 
  47. if ($args && !is_array($args)) { 
  48. $args = array($args); 
  49.  
  50. // Over-rides default call method, adds signature check 
  51. if (!$this->hasMethod($methodname)) { 
  52. return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); 
  53. $method = $this->callbacks[$methodname]; 
  54. $signature = $this->signatures[$methodname]; 
  55. $returnType = array_shift($signature); 
  56.  
  57. // Check the number of arguments 
  58. if (count($args) != count($signature)) { 
  59. return new IXR_Error(-32602, 'server error. wrong number of method parameters'); 
  60.  
  61. // Check the argument types 
  62. $ok = true; 
  63. $argsbackup = $args; 
  64. for ($i = 0, $j = count($args); $i < $j; $i++) { 
  65. $arg = array_shift($args); 
  66. $type = array_shift($signature); 
  67. switch ($type) { 
  68. case 'int': 
  69. case 'i4': 
  70. if (is_array($arg) || !is_int($arg)) { 
  71. $ok = false; 
  72. break; 
  73. case 'base64': 
  74. case 'string': 
  75. if (!is_string($arg)) { 
  76. $ok = false; 
  77. break; 
  78. case 'boolean': 
  79. if ($arg !== false && $arg !== true) { 
  80. $ok = false; 
  81. break; 
  82. case 'float': 
  83. case 'double': 
  84. if (!is_float($arg)) { 
  85. $ok = false; 
  86. break; 
  87. case 'date': 
  88. case 'dateTime.iso8601': 
  89. if (!is_a($arg, 'IXR_Date')) { 
  90. $ok = false; 
  91. break; 
  92. if (!$ok) { 
  93. return new IXR_Error(-32602, 'server error. invalid method parameters'); 
  94. // It passed the test - run the "real" method call 
  95. return parent::call($methodname, $argsbackup); 
  96.  
  97. function methodSignature($method) 
  98. if (!$this->hasMethod($method)) { 
  99. return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); 
  100. // We should be returning an array of types 
  101. $types = $this->signatures[$method]; 
  102. $return = array(); 
  103. foreach ($types as $type) { 
  104. switch ($type) { 
  105. case 'string': 
  106. $return[] = 'string'; 
  107. break; 
  108. case 'int': 
  109. case 'i4': 
  110. $return[] = 42; 
  111. break; 
  112. case 'double': 
  113. $return[] = 3.1415; 
  114. break; 
  115. case 'dateTime.iso8601': 
  116. $return[] = new IXR_Date(time()); 
  117. break; 
  118. case 'boolean': 
  119. $return[] = true; 
  120. break; 
  121. case 'base64': 
  122. $return[] = new IXR_Base64('base64'); 
  123. break; 
  124. case 'array': 
  125. $return[] = array('array'); 
  126. break; 
  127. case 'struct': 
  128. $return[] = array('struct' => 'struct'); 
  129. break; 
  130. return $return; 
  131.  
  132. function methodHelp($method) 
  133. return $this->help[$method];