IXR_IntrospectionServer

IXR_IntrospectionServer.

Defined (1)

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

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