4 * IXR_IntrospectionServer
9 class IXR_IntrospectionServer extends IXR_Server
17 function __construct()
19 $this->setCallbacks();
20 $this->setCapabilities();
21 $this->capabilities['introspection'] = array(
22 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
26 'system.methodSignature',
27 'this:methodSignature',
28 array('array', 'string'),
29 'Returns an array describing the return type and required parameters of a method'
32 'system.getCapabilities',
33 'this:getCapabilities',
35 'Returns a struct describing the XML-RPC specifications supported by this server'
41 'Returns an array of available methods on this server'
46 array('string', 'string'),
47 'Returns a documentation string for the specified method'
54 public function IXR_IntrospectionServer() {
58 function addCallback($method, $callback, $args, $help)
60 $this->callbacks[$method] = $callback;
61 $this->signatures[$method] = $args;
62 $this->help[$method] = $help;
65 function call($methodname, $args)
67 // Make sure it's in an array
68 if ($args && !is_array($args)) {
72 // Over-rides default call method, adds signature check
73 if (!$this->hasMethod($methodname)) {
74 return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
76 $method = $this->callbacks[$methodname];
77 $signature = $this->signatures[$methodname];
78 $returnType = array_shift($signature);
80 // Check the number of arguments
81 if (count($args) != count($signature)) {
82 return new IXR_Error(-32602, 'server error. wrong number of method parameters');
85 // Check the argument types
88 for ($i = 0, $j = count($args); $i < $j; $i++) {
89 $arg = array_shift($args);
90 $type = array_shift($signature);
94 if (is_array($arg) || !is_int($arg)) {
100 if (!is_string($arg)) {
105 if ($arg !== false && $arg !== true) {
111 if (!is_float($arg)) {
116 case 'dateTime.iso8601':
117 if (!is_a($arg, 'IXR_Date')) {
123 return new IXR_Error(-32602, 'server error. invalid method parameters');
126 // It passed the test - run the "real" method call
127 return parent::call($methodname, $argsbackup);
130 function methodSignature($method)
132 if (!$this->hasMethod($method)) {
133 return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
135 // We should be returning an array of types
136 $types = $this->signatures[$method];
138 foreach ($types as $type) {
141 $return[] = 'string';
150 case 'dateTime.iso8601':
151 $return[] = new IXR_Date(time());
157 $return[] = new IXR_Base64('base64');
160 $return[] = array('array');
163 $return[] = array('struct' => 'struct');
170 function methodHelp($method)
172 return $this->help[$method];