Remove from response the nillable elements. Fix namespace declaration in the xml response

This commit is contained in:
Gianluigi 'cocciagialla' Mammarella
2019-06-26 18:53:59 +02:00
parent 9fc58e4388
commit fea1093bed
2 changed files with 25 additions and 2 deletions

View File

@ -99,7 +99,30 @@ class SoapServer extends \SoapServer
ob_start();
parent::handle($soapRequest->getContent());
$response = ob_get_clean();
$response = str_replace('SOAP-ENV', 'soap', $response);
$dom = \DOMDocument::loadXML($response);
/** @var \DOMElement $envelop */
$envelop = $dom->childNodes->item(0);
$ns1 = $envelop->getAttribute('xmlns:ns1');
$envelop->removeAttributeNS($ns1, 'ns1');
$envelop->prefix = 'soap';
$envelop->setAttribute('soap:encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/');
$envelop->setAttribute('xmlns:soapenc', 'http://schemas.xmlsoap.org/soap/encoding/');
$envelop->setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
/** @var \DOMElement $body */
$body = $envelop->childNodes->item(0);
$body->prefix = 'soap';
/** @var \DOMElement $responseRoot */
$responseRoot = $body->childNodes->item(0);
$responseRoot->setAttribute('xmlns', $ns1);
$envelop->removeAttributeNS('http://schemas.xmlsoap.org/soap/envelope/', 'SOAP-ENV');
$response = $dom->saveXML();
// Remove headers added by SoapServer::handle() method
header_remove('Content-Length');