_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]; } /** * Set skip system lookup flag * * @param bool $flag * @return Zend_XmlRpc_Client */ public function setSkipSystemLookup($flag = true) { $this->_skipSystemLookup = (bool) $flag; return $this; } /** * Skip system lookup when determining if parameter should be array or struct? * * @return bool */ public function skipSystemLookup() { return $this->_skipSystemLookup; } /** * 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(); if($http->getUri() === null) { $http->setUri($this->_serverAddress); } $http->setHeaders(array( 'Content-Type: text/xml; charset=utf-8', 'User-Agent: Zend_XmlRpc_Client', 'Accept: text/xml', )); $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()) { if (!$this->skipSystemLookup() && ('system.' != substr($method, 0, 7))) { // Ensure empty array/struct params are cast correctly // If system.* methods are not available, bypass. (ZF-2978) $success = true; try { $signatures = $this->getIntrospector()->getMethodSignature($method); } catch (Zend_XmlRpc_Exception $e) { $success = false; } if ($success) { foreach ($params as $key => $param) { if (is_array($param) && empty($param)) { $type = 'array'; foreach ($signatures as $signature) { if (!is_array($signature)) { continue; } if (array_key_exists($key + 1, $signature)) { $type = $signature[$key + 1]; $type = (in_array($type, array('array', 'struct'))) ? $type : 'array'; break; } } $params[$key] = array( 'type' => $type, 'value' => $param ); } } } } $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(); } }