Ejemplo n.º 1
0
 /**
  * Fixes the XML based on the parameters specified in the constructor.
  * @param string $request the raw request produced by the SOAP client
  * @param array $arguments the arguments passed to the SOAP method
  * @param array $headers the headers used in the request
  * @return string the prepared request ready to be sent to the server
  */
 public function FixXml($request, array $arguments, array $headers)
 {
     $requestDom = XmlUtils::GetDomFromXml($request);
     $xpath = new DOMXPath($requestDom);
     // Fix headers.
     $headersDomNodes = $xpath->query("//*[local-name()='Envelope']/*[local-name()='Header']/*");
     $this->FixXmlNodes($headersDomNodes, $headers, $xpath);
     // Fix body.
     $argumentsDomNodes = $xpath->query("//*[local-name()='Envelope']/*[local-name()='Body']/*");
     $this->FixXmlNodes($argumentsDomNodes, $arguments, $xpath);
     // Remove empty headers.
     if ($this->removeEmptyElements) {
         $this->RemoveEmptyHeaderElements($xpath);
     }
     return $requestDom->saveXML();
 }
Ejemplo n.º 2
0
 /**
  * Tries to parse the error response xml from the AdWords API server as an
  * object. This method is used in parsing all error responses when API
  * version >= v201209, and in other versions when apiMode header is mentioned
  * in the request headers.
  *
  * @param String $responseXml the error response xml
  * @return Object the parsed error object, or null if the response cannot
  * be parsed.
  */
 private static function ParseApiErrorXml($responseXml)
 {
     $retval = null;
     try {
         $doc = XmlUtils::GetDomFromXml($responseXml);
         $retval = XmlUtils::ConvertDocumentToObject($doc);
         if (!is_array($retval->ApiError)) {
             $retval->ApiError = array($retval->ApiError);
         }
     } catch (Exception $e) {
         // There was a parse exception and hence this response cannot be
         // interpreted as an xml.
     }
     return $retval;
 }
Ejemplo n.º 3
0
 /**
  * A typemap conversion function for parsing long values in SOAP responses.
  * @param string $xml the XML snippet containing the long value.
  * @return mixed the inner long value as an integer, float, or string
  */
 public static function TypemapLongFromXml($xml)
 {
     $document = XmlUtils::GetDomFromXml($xml);
     $tag = $document->documentElement->localName;
     $value = $document->documentElement->nodeValue;
     $isIdField = preg_match('/^id$|Id$|ID$/', $tag);
     if (!$isIdField) {
         if (strcmp(strval(intval($value)), $value) === 0) {
             return intval($value);
         } elseif (strcmp(sprintf('%.0f', floatval($value)), $value) === 0) {
             return floatval($value);
         }
     }
     return $value;
 }
 /**
  * Get an Asset as an XML Dom.
  * @param string $assetName the XML asset name
  * @param null|string $ext the extension of the asset, if applicable
  * @return string the contents of the asset
  * @throws InvalidArgumentException if theres an issue finding the file
  * @throws DOMException if the DOM could not be loaded
  */
 public function getAssetAsDom($assetName, $ext = null)
 {
     return XmlUtils::GetDomFromXml($this->getAsset($assetName, $ext));
 }
Ejemplo n.º 5
0
 /**
  * Test converting a DOM document to an object.
  * @param string $xml the XML to convert
  * @param Object $expected the expected result of the conversion
  * @covers XmlUtils::ConvertDocumentToObject
  * @covers XmlUtils::ConvertElementToObject
  * @covers XmlUtils::ConvertNodeValueToObject
  * @dataProvider XmlToObjectProvider
  */
 public function testConvertDocumentToObject($xml, $expected)
 {
     $document = XmlUtils::GetDomFromXml($xml);
     $result = XmlUtils::ConvertDocumentToObject($document);
     $this->assertEquals($expected, $result);
 }
 /**
  * Converts an XML representation to objects of proper classes using many
  * types of information, e.g., the xsi:type attribute.
  *
  * @param string $xml the XML representation to be deserialized
  * @return mixed the converted object
  */
 public function ConvertXmlToObject($xml)
 {
     return self::ConvertElementToObject(XmlUtils::GetDomFromXml($xml)->documentElement);
 }
Ejemplo n.º 7
0
 /**
  * @covers XmlUtils::GetXmlFromDom
  * @dataProvider ValidXmlProvider
  */
 public function testGetXmlFromDom($xml)
 {
     $document = XmlUtils::GetDomFromXml($xml);
     $result = XmlUtils::GetXmlFromDom($document);
     $this->assertTrue(!empty($result));
 }