diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/XmlRpc/Response.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/XmlRpc/Response.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,251 @@ +setReturnValue($return, $type); + } + + /** + * Set encoding to use in response + * + * @param string $encoding + * @return Zend_XmlRpc_Response + */ + public function setEncoding($encoding) + { + $this->_encoding = $encoding; + Zend_XmlRpc_Value::setEncoding($encoding); + return $this; + } + + /** + * Retrieve current response encoding + * + * @return string + */ + public function getEncoding() + { + return $this->_encoding; + } + + /** + * Set the return value + * + * Sets the return value, with optional type hinting if provided. + * + * @param mixed $value + * @param string $type + * @return void + */ + public function setReturnValue($value, $type = null) + { + $this->_return = $value; + $this->_type = (string) $type; + } + + /** + * Retrieve the return value + * + * @return mixed + */ + public function getReturnValue() + { + return $this->_return; + } + + /** + * Retrieve the XMLRPC value for the return value + * + * @return Zend_XmlRpc_Value + */ + protected function _getXmlRpcReturn() + { + return Zend_XmlRpc_Value::getXmlRpcValue($this->_return); + } + + /** + * Is the response a fault response? + * + * @return boolean + */ + public function isFault() + { + return $this->_fault instanceof Zend_XmlRpc_Fault; + } + + /** + * Returns the fault, if any. + * + * @return null|Zend_XmlRpc_Fault + */ + public function getFault() + { + return $this->_fault; + } + + /** + * Load a response from an XML response + * + * Attempts to load a response from an XMLRPC response, autodetecting if it + * is a fault response. + * + * @param string $response + * @return boolean True if a valid XMLRPC response, false if a fault + * response or invalid input + */ + public function loadXml($response) + { + if (!is_string($response)) { + $this->_fault = new Zend_XmlRpc_Fault(650); + $this->_fault->setEncoding($this->getEncoding()); + return false; + } + + try { + $useInternalXmlErrors = libxml_use_internal_errors(true); + $xml = new SimpleXMLElement($response); + libxml_use_internal_errors($useInternalXmlErrors); + } catch (Exception $e) { + libxml_use_internal_errors($useInternalXmlErrors); + // Not valid XML + $this->_fault = new Zend_XmlRpc_Fault(651); + $this->_fault->setEncoding($this->getEncoding()); + return false; + } + + if (!empty($xml->fault)) { + // fault response + $this->_fault = new Zend_XmlRpc_Fault(); + $this->_fault->setEncoding($this->getEncoding()); + $this->_fault->loadXml($response); + return false; + } + + if (empty($xml->params)) { + // Invalid response + $this->_fault = new Zend_XmlRpc_Fault(652); + $this->_fault->setEncoding($this->getEncoding()); + return false; + } + + try { + if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) { + throw new Zend_XmlRpc_Value_Exception('Missing XML-RPC value in XML'); + } + $valueXml = $xml->params->param->value->asXML(); + $value = Zend_XmlRpc_Value::getXmlRpcValue($valueXml, Zend_XmlRpc_Value::XML_STRING); + } catch (Zend_XmlRpc_Value_Exception $e) { + $this->_fault = new Zend_XmlRpc_Fault(653); + $this->_fault->setEncoding($this->getEncoding()); + return false; + } + + $this->setReturnValue($value->getValue()); + return true; + } + + /** + * Return response as XML + * + * @return string + */ + public function saveXml() + { + $value = $this->_getXmlRpcReturn(); + $generator = Zend_XmlRpc_Value::getGenerator(); + $generator->openElement('methodResponse') + ->openElement('params') + ->openElement('param'); + $value->generateXml(); + $generator->closeElement('param') + ->closeElement('params') + ->closeElement('methodResponse'); + + return $generator->flush(); + } + + /** + * Return XML response + * + * @return string + */ + public function __toString() + { + return $this->saveXML(); + } +}