Exemplo n.º 1
0
 /**
  * Gets the struct value from the provided value DOM element
  * @param DOMElement $element The DOM element of the value
  * @return array
  * @throws zibo\library\xmlrpc\exception\XmlRpcException when one of the child member elements does not contain a name or value
  */
 private function parseStructElement(DOMElement $element)
 {
     $memberElements = $element->childNodes;
     $result = array();
     foreach ($memberElements as $memberElement) {
         $nameElement = $memberElement->getElementsByTagName('name')->item(0);
         if (!$nameElement) {
             throw new XmlRpcException('Invalid member value, no name found');
         }
         $valueElement = $memberElement->getElementsByTagName('value')->item(0);
         if (!$valueElement) {
             throw new XmlRpcException('Invalid member value, no value found');
         }
         $parameter = new Value($valueElement);
         $result[$nameElement->textContent] = $parameter->getValue();
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Gets and validates the provided parameter values
  * @param array $parameters Array with Value objects
  * @param array $parameterTypes Array with the expected types for the provided values
  * @return array Array with the actual values
  * @throws zibo\library\xmlrpc\exception\XmlRpcException when the number of parameters is not the same as the number of expected parameters
  * @throws zibo\library\xmlrpc\exception\XmlRpcException when one of the parameters is not of the expected type and could not be converted to it
  */
 private function getCallbackParameters($parameters, $parameterTypes)
 {
     $result = array();
     $countParameters = count($parameters);
     $countParameterTypes = count($parameterTypes);
     if ($countParameters != $countParameterTypes) {
         throw new XmlRpcException('Incorrect parameter count: expecting ' . $countParameterTypes . ' parameters but got ' . $countParameters . '.');
     }
     for ($i = 0; $i < $countParameters; $i++) {
         $expectedType = $parameterTypes[$i];
         $type = $parameters[$i]->getType();
         if ($expectedType != null && $type != $expectedType) {
             try {
                 $value = $parameters[$i]->getValue();
                 $value = Value::convertValue($value, $type, $expectedType);
                 $parameters[$i] = new Value($value, $type);
             } catch (Exception $e) {
                 throw new XmlRpcException('Parameter ' . ($i + 1) . ' is of type ' . $type . ', expecting type ' . $expectedType . ' (' . $e->getMessage() . ')', 0, $e);
             }
         }
         $result[] = $parameters[$i]->getValue();
     }
     return $result;
 }
Exemplo n.º 3
0
 public function testGetXmlElementWithEmptyStruct()
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $value = new Value(array(), Value::TYPE_STRUCT);
     $valueElement = $dom->createElement('value');
     $element = $dom->createElement('nil');
     $valueElement->appendChild($element);
     $parameterElement = $value->getXmlElement();
     $this->assertNotNull($parameterElement);
     $this->assertEquals($valueElement->ownerDocument->saveXML($valueElement), $parameterElement->ownerDocument->saveXml($parameterElement));
 }
Exemplo n.º 4
0
 /**
  * Parses a error response DOM element into this object
  * @param DOMElement $responseElement The response element
  * @return null
  * @throws zibo\library\xmlrpc\exception\XmlRpcException when the provided element is not a valid response element
  */
 private function parseFaultElement(DOMElement $responseElement)
 {
     $faultElement = $responseElement->getElementsByTagname('fault')->item(0);
     $valueElement = $faultElement->getElementsByTagName('value')->item(0);
     if (!$valueElement) {
         throw new XmlRpcException('Invalid fault response, fault tag has no value');
     }
     $valueObject = new Value($valueElement);
     $value = $valueObject->getValue();
     $this->errorCode = $value['faultCode'];
     $this->errorMessage = $value['faultString'];
 }