/** * Alter slightly from parent class to allow usage of custom wsdl files: * pass wsdl as 2nd param instead of an array, and wsdl version as 3rd param (defaulting to 1) */ function registerFunction($name, $params = null, $result = 'mixed', $description = '') { if (is_string($params)) { if ($return = parent::registerFunction($name, null, 'mixed', $description)) { $version = $result == 2 ? 2 : 1; $this->wsdl[$name][$version] = $params; } } else { $return = parent::registerFunction($name, $params, $result, $description); } return $return; }
/** * 3rd param is a hack used to allow a jsonrpc server to take advantage of this method */ function handleInternalRequest($functionName, $params, $server = null) { if ($server === null) { $server = $this; } switch ($functionName) { case 'system.listMethods': if (count($params) != 0) { return new ggWebservicesFault(self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING); } return $server->registeredMethods(); case 'system.methodSignature': if (count($params) != 1 || !is_string($params[0])) { return new ggWebservicesFault(self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING); } if (in_array($params[0], $server->internalMethods)) { switch ($params[0]) { case 'system.listMethods': return array(array('array')); case 'system.methodSignature': return array(array('array', 'string')); case 'system.methodHelp': return array(array('string', 'string')); case 'system.multicall': return array(array('array', 'array')); } } if (!array_key_exists($params[0], $server->FunctionList)) { return new ggWebservicesFault(self::INVALIDINTROSPECTIONERROR, self::INVALIDINTROSPECTIONSTRING); } $results = array(); foreach ($server->FunctionList[$params[0]] as $syntax) { if ($syntax['in'] !== null) { $syntax['in'] = array_values($syntax['in']); array_unshift($syntax['in'], $syntax['out']); $results[] = $syntax['in']; } } return $results; case 'system.methodHelp': if (count($params) != 1 || !is_string($params[0])) { return new ggWebservicesFault(self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING); } if (in_array($params[0], $server->internalMethods)) { switch ($params[0]) { case 'system.listMethods': return 'This method lists all the methods that the server knows how to dispatch'; case 'system.methodSignature': return 'Returns an array of known signatures (an array of arrays) for the method name passed. First member of each array is the return type'; case 'system.methodHelp': return 'Returns help text if defined for the method passed, otherwise returns an empty string'; case 'system.multicall': return 'Boxcar multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details'; } } if (!array_key_exists($params[0], $server->FunctionDescription)) { return new ggWebservicesFault(self::INVALIDINTROSPECTIONERROR, self::INVALIDINTROSPECTIONSTRING); } return $server->FunctionDescription[$params[0]]; case 'system.multicall': // validate first the multicall syntax if (count($params) != 1 || !is_array($params[0])) { return new ggWebservicesFault(self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING); } foreach ($params[0] as $request) { if (!is_array($request) || !array_key_exists('methodName', $request) || !is_string($request['methodName']) || !array_key_exists('params', $request) || !is_array($request['params'])) { return new ggWebservicesFault(self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING); } } // then execute all methods $results = array(); foreach ($params[0] as $request) { $resp = $server->handleRequest($request['methodName'], $request['params']); if (is_a($resp, 'ggWebservicesFault')) { $results[] = array('faultCode' => $resp->faultCode(), 'faultString' => $resp->faultString()); } else { $results[] = $resp; } } return $results; default: return parent::handleInternalRequest($functionName, $params); } }
/** * Rest protocol uses named parameters, hence the calling convention is different: * the php functions are expected to receive an array as the only param, containing * in it all actual parameters with their names. */ function handleRequest($functionName, $params) { return parent::handleRequest($functionName, array($params)); }