示例#1
0
文件: Request.php 项目: Rovak/zf2
 /**
  * Retrieve method parameters as XMLRPC values
  *
  * @return array
  */
 protected function _getXmlRpcParams()
 {
     $params = array();
     if (is_array($this->xmlRpcParams)) {
         foreach ($this->xmlRpcParams as $param) {
             $value = $param['value'];
             $type = $param['type'] ?: AbstractValue::AUTO_DETECT_TYPE;
             if (!$value instanceof AbstractValue) {
                 $value = AbstractValue::getXmlRpcValue($value, $type);
             }
             $params[] = $value;
         }
     }
     return $params;
 }
示例#2
0
 /**
  * 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 Fault(650);
         $this->_fault->setEncoding($this->getEncoding());
         return false;
     }
     // @see ZF-12293 - disable external entities for security purposes
     $loadEntities = libxml_disable_entity_loader(true);
     $useInternalXmlErrors = libxml_use_internal_errors(true);
     try {
         $xml = new \SimpleXMLElement($response);
         libxml_disable_entity_loader($loadEntities);
         libxml_use_internal_errors($useInternalXmlErrors);
     } catch (\Exception $e) {
         libxml_disable_entity_loader($loadEntities);
         libxml_use_internal_errors($useInternalXmlErrors);
         // Not valid XML
         $this->_fault = new Fault(651);
         $this->_fault->setEncoding($this->getEncoding());
         return false;
     }
     if (!empty($xml->fault)) {
         // fault response
         $this->_fault = new Fault();
         $this->_fault->setEncoding($this->getEncoding());
         $this->_fault->loadXml($response);
         return false;
     }
     if (empty($xml->params)) {
         // Invalid response
         $this->_fault = new 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 Exception\ValueException('Missing XML-RPC value in XML');
         }
         $valueXml = $xml->params->param->value->asXML();
         $value = AbstractValue::getXmlRpcValue($valueXml, AbstractValue::XML_STRING);
     } catch (Exception\ValueException $e) {
         $this->_fault = new Fault(653);
         $this->_fault->setEncoding($this->getEncoding());
         return false;
     }
     $this->setReturnValue($value->getValue());
     return true;
 }
示例#3
0
 /**
  * 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 Fault(650);
         $this->fault->setEncoding($this->getEncoding());
         return false;
     }
     // @see ZF-12293 - disable external entities for security purposes
     $loadEntities = libxml_disable_entity_loader(true);
     $useInternalXmlErrors = libxml_use_internal_errors(true);
     try {
         $dom = new \DOMDocument();
         $dom->loadXML($response);
         foreach ($dom->childNodes as $child) {
             if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
                 throw new Exception\ValueException('Invalid XML: Detected use of illegal DOCTYPE');
             }
         }
         // TODO: Locate why this passes tests but a simplexml import doesn't
         //$xml = simplexml_import_dom($dom);
         $xml = new \SimpleXMLElement($response);
         libxml_disable_entity_loader($loadEntities);
         libxml_use_internal_errors($useInternalXmlErrors);
     } catch (\Exception $e) {
         libxml_disable_entity_loader($loadEntities);
         libxml_use_internal_errors($useInternalXmlErrors);
         // Not valid XML
         $this->fault = new Fault(651);
         $this->fault->setEncoding($this->getEncoding());
         return false;
     }
     if (!empty($xml->fault)) {
         // fault response
         $this->fault = new Fault();
         $this->fault->setEncoding($this->getEncoding());
         $this->fault->loadXml($response);
         return false;
     }
     if (empty($xml->params)) {
         // Invalid response
         $this->fault = new 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 Exception\ValueException('Missing XML-RPC value in XML');
         }
         $valueXml = $xml->params->param->value->asXML();
         $value = AbstractValue::getXmlRpcValue($valueXml, AbstractValue::XML_STRING);
     } catch (Exception\ValueException $e) {
         $this->fault = new Fault(653);
         $this->fault->setEncoding($this->getEncoding());
         return false;
     }
     $this->setReturnValue($value->getValue());
     return true;
 }
示例#4
0
文件: Fault.php 项目: Baft/Zend-Form
 /**
  * Serialize fault to XML
  *
  * @return string
  */
 public function saveXml()
 {
     // Create fault value
     $faultStruct = array('faultCode' => $this->getCode(), 'faultString' => $this->getMessage());
     $value = AbstractValue::getXmlRpcValue($faultStruct);
     $generator = AbstractValue::getGenerator();
     $generator->openElement('methodResponse')->openElement('fault');
     $value->generateXml();
     $generator->closeElement('fault')->closeElement('methodResponse');
     return $generator->flush();
 }