/wp-includes/IXR/class-IXR-introspectionserver.php

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