public function testInvokePhpxmlrpcTestServerExampleEchoesString() { $client = new Client(self::PHPXMLRPC_TEST_SERVER); $request = new Request(self::PHPXMLRPC_TEST_METHOD); $string = 'testing 1 2 3'; $request->addParameter($string); $response = $client->invoke($request); $this->assertSame($string, $response->getValue()); }
/** * Get a XML-RPC request for the provided method and parameters * @param string $method full name of the method * @param string $parameters submitted parameters in string format, ready to be parsed * @return zibo\library\xmlrpc\Request the request for the XML RPC server * @throws zibo\library\validation\exception\ValidationException when the parameters could not be parsed */ private function getXmlrpcRequest($method, $parameters) { $request = new Request($method); if (!$parameters) { return $request; } $parser = new ParameterParser(); try { $parameters = $parser->parse($parameters); } catch (ZiboException $exception) { $error = new ValidationError(self::TRANSLATION_ERROR_PARAMETERS, 'Could not parse the parameters: %error%', array('error' => $exception->getMessage())); $validationException = new ValidationException(); $validationException->addErrors(ClientForm::FIELD_PARAMETERS, array($error)); throw $validationException; } foreach ($parameters as $parameter) { $request->addParameter($parameter); } return $request; }
/** * Gets a module from the repository * @param string $namespace The namespace of the module * @param string $name The name of the module * @return Module * @throws Exception when the module could not be retrieved */ public function getModule($namespace, $name) { $request = new Request(RepositoryModule::SERVICE_PREFIX . RepositoryModule::SERVICE_MODULE_INFO); $request->addParameter(new Value($namespace)); $request->addParameter(new Value($name)); $exception = null; $module = null; foreach ($this->clients as $url => $client) { $response = $client->invoke($request); if ($response->getErrorCode() !== 0) { if (!$exception) { $exception = new ZiboException('Repository (' . $url . ') returned a fault with code ' . $response->getErrorCode() . ' and message: ' . $response->getErrorMessage()); } else { $exception = new ZiboException('Repository (' . $url . ') returned a fault with code ' . $response->getErrorCode() . ' and message: ' . $response->getErrorMessage(), 0, $exception); } continue; } $module = $this->getModuleFromArray($response->getValue()); $module->setRepository($url); break; } if ($exception) { throw $exception; } return $module; }
/** * Gets the request from the provided request structure * @param array $requestStruct Array with a key methodName and a key params with their respective values * @return Request */ protected function getRequestFromStruct(array $requestStruct) { if (!isset($requestStruct[self::MULTICALL_METHOD_NAME])) { throw new XmlRpcException('Could not find element ' . self::MULTICALL_METHOD_NAME . ' in the request struct.'); } $methodName = $requestStruct[self::MULTICALL_METHOD_NAME]; if (empty($methodName) || !is_string($methodName)) { throw new XmlRpcException('Provided method name is empty or invalid.'); } $parameters = array(); if (isset($requestStruct[self::MULTICALL_PARAMS])) { if (!is_array($requestStruct[self::MULTICALL_PARAMS])) { throw new XmlRpcException('Provided parameters are invalid, array expected.'); } $parameters = $requestStruct[self::MULTICALL_PARAMS]; } $request = new Request($methodName); foreach ($parameters as $parameter) { $request->addParameter($parameter); } return $request; }