/** * Performs some fixes on the XML request before sending it out. * * @param string $request the request to be modified * @param array $arguments the arguments passed to the SOAP method * @param array $headers the headers used in the request * @return string the XML request ready to be sent to the server */ protected function PrepareRequest($request, array $arguments, array $headers) { $addXsiTypes = $this->user->GetForceAddXsiTypes(); $fixer = new SoapRequestXmlFixer($addXsiTypes, false, true); return $fixer->FixXml($request, $arguments, $headers); }
/** * Tests replacing element references. */ public function testReplaceElementReference() { $request = <<<EOT <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <foo> <value>foo</value> </foo> </soapenv:Header> <soapenv:Body> <bar id="1234"> <value>bar</value> </bar> <bar href="#1234" /> </soapenv:Body> </soapenv:Envelope> EOT; $expected = <<<EOT <?xml version="1.0"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <foo> <value>foo</value> </foo> </soapenv:Header> <soapenv:Body> <bar> <value>bar</value> </bar> <bar> <value>bar</value> </bar> </soapenv:Body> </soapenv:Envelope> EOT; $foo = new Foo(); $foo->value = 'foo'; $bar1 = new Bar(); $bar1->value = 'bar'; $bar2 = new Bar(); $bar2->value = 'bar'; $headers[] = $foo; $arguments[] = $bar1; $arguments[] = $bar2; $fixer = new SoapRequestXmlFixer(false, false, true); $result = $fixer->FixXml($request, $arguments, $headers); $this->assertEquals($expected, $result); }
/** * Depending on the version of PHP, the xsi:types need to be added and empty * tags may need to be removed. The SoapRequestXmlFixer class can facilitate * these changes. * @param string $request the request to be modified * @param array $arguments the arguments passed to the SOAP method * @param array $headers the headers used in the request * @return string the XML request ready to be sent to the server * @access protected */ protected function PrepareRequest($request, array $arguments, array $headers) { $addXsiTypes = $this->user->GetForceAddXsiTypes(); $removeEmptyElements = FALSE; $replaceReferences = FALSE; if (version_compare(PHP_VERSION, '5.2.0', '<')) { trigger_error('The minimum required version of this client library' . ' is 5.2.0.', E_USER_ERROR); } // If FORCE_ADD_XSI_TYPES was unset, then set it based on PHP version if ($addXsiTypes === null) { if (version_compare(PHP_VERSION, '5.2.6', '<') || PHP_OS == 'Darwin' && version_compare(PHP_VERSION, '5.3.0', '<')) { $addXsiTypes = TRUE; } else { // If FORCE_ADD_XSI_TYPES was not set, and we didn't find an applicable // version, then set it to FALSE by default. $addXsiTypes = FALSE; } } $removeEmptyElements = version_compare(PHP_VERSION, '5.2.3', '<'); $replaceReferences = version_compare(PHP_VERSION, '5.2.2', '>='); if ($addXsiTypes || $removeEmptyElements || $replaceReferences) { $fixer = new SoapRequestXmlFixer($addXsiTypes, $removeEmptyElements, $replaceReferences); return $fixer->FixXml($request, $arguments, $headers); } else { // Empty string is appended to "save" the XML from being deleted. return $request . ''; } }
/** * Depending on the version of PHP, the xsi:types need to be added and empty * tags may need to be removed. The SoapRequestXmlFixer class can facilitate * these changes. * @param string $request the request to be modified * @param array $arguments the arguments passed to the SOAP method * @param array $headers the headers used in the request * @return string the XML request ready to be sent to the server * @access protected */ protected function PrepareRequest($request, array $arguments, array $headers) { $addXsiTypes = FALSE; $removeEmptyElements = FALSE; $replaceReferences = FALSE; if (version_compare(PHP_VERSION, '5.2.0', '<')) { trigger_error('The minimum required version of this client library' . ' is 5.2.0.', E_USER_ERROR); } $addXsiTypes = version_compare(PHP_VERSION, '5.2.7', '<') || PHP_OS == 'Darwin'; $removeEmptyElements = version_compare(PHP_VERSION, '5.2.3', '<'); $replaceReferences = version_compare(PHP_VERSION, '5.2.2', '>='); if ($addXsiTypes || $removeEmptyElements || $replaceReferences) { $fixer = new SoapRequestXmlFixer($addXsiTypes, $removeEmptyElements, $replaceReferences); return $fixer->FixXml($request, $arguments, $headers); } else { // Empty string is appended to "save" the XML from being deleted. return $request . ''; } }