_httpClient = new Zend_Http_Client(); } else { $this->_httpClient = $httpClient; } $this->_introspector = new Zend_XmlRpc_Client_ServerIntrospection($this); $this->_serverAddress = $server; } /** * Sets the HTTP client object to use for connecting the XML-RPC server. * * @param Zend_Http_Client $httpClient * @return Zend_Http_Client */ public function setHttpClient(Zend_Http_Client $httpClient) { return $this->_httpClient = $httpClient; } /** * Gets the HTTP client object. * * @return Zend_Http_Client */ public function getHttpClient() { return $this->_httpClient; } /** * Sets the object used to introspect remote servers * * @param Zend_XmlRpc_Client_ServerIntrospection * @return Zend_XmlRpc_Client_ServerIntrospection */ public function setIntrospector(Zend_XmlRpc_Client_ServerIntrospection $introspector) { return $this->_introspector = $introspector; } /** * Gets the introspection object. * * @return Zend_XmlRpc_Client_ServerIntrospection */ public function getIntrospector() { return $this->_introspector; } /** * The request of the last method call * * @return Zend_XmlRpc_Request */ public function getLastRequest() { return $this->_lastRequest; } /** * The response received from the last method call * * @return Zend_XmlRpc_Response */ public function getLastResponse() { return $this->_lastResponse; } /** * Returns a proxy object for more convenient method calls * * @param $namespace Namespace to proxy or empty string for none * @return Zend_XmlRpc_Client_ServerProxy */ public function getProxy($namespace = '') { if (empty($this->_proxyCache[$namespace])) { $proxy = new Zend_XmlRpc_Client_ServerProxy($this, $namespace); $this->_proxyCache[$namespace] = $proxy; } return $this->_proxyCache[$namespace]; } /** * Perform an XML-RPC request and return a response. * * @param Zend_XmlRpc_Request $request * @param null|Zend_XmlRpc_Response $response * @return void */ public function doRequest($request, $response = null) { $this->_lastRequest = $request; iconv_set_encoding('input_encoding', 'UTF-8'); iconv_set_encoding('output_encoding', 'UTF-8'); iconv_set_encoding('internal_encoding', 'UTF-8'); $http = $this->getHttpClient(); $http->setUri($this->_serverAddress); $http->setHeaders(array( 'Content-Type: text/xml; charset=utf-8', 'User-Agent: Zend_XmlRpc_Client' )); $xml = $this->_lastRequest->__toString(); $http->setRawData($xml); $httpResponse = $http->request(Zend_Http_Client::POST); if (! $httpResponse->isSuccessful()) { throw new Zend_XmlRpc_Client_HttpException( $httpResponse->getMessage(), $httpResponse->getStatus()); } if ($response === null) { $response = new Zend_XmlRpc_Response(); } $this->_lastResponse = $response; $this->_lastResponse->loadXml($httpResponse->getBody()); } /** * Send an XML-RPC request to the service (for a specific method) * * @param string $method Name of the method we want to call * @param array $params Array of parameters for the method * @throws Zend_Http_Client_FaultException */ public function call($method, $params=array()) { $request = new Zend_XmlRpc_Request($method, $params); $this->doRequest($request); if ($this->_lastResponse->isFault()) { $fault = $this->_lastResponse->getFault(); throw new Zend_XmlRpc_Client_FaultException($fault->getMessage(), $fault->getCode()); } return $this->_lastResponse->getReturnValue(); } }