SoapClient::trace = SoapClientOptions::SOAP_CLIENT_TRACE_OFF fixed when SoapFault is thrown
Incompatible changes: 1) Default SoapClientOptionsBuilder method now sets tracing to ON and 2) SoapResponse now contains request in all calls so that SoapRequestFactory interface had to be changed.
This commit is contained in:
@ -95,7 +95,7 @@ class SoapClient extends \SoapClient
|
||||
|
||||
} catch (SoapFault $soapFault) {
|
||||
if (SoapFaultSourceGetter::isNativeSoapFault($soapFault)) {
|
||||
$soapFault = $this->decorateNativeSoapFault($soapFault);
|
||||
$soapFault = $this->decorateNativeSoapFaultWithSoapResponseTracingData($soapFault);
|
||||
}
|
||||
|
||||
throw $soapFault;
|
||||
@ -257,6 +257,23 @@ class SoapClient extends \SoapClient
|
||||
return $loadedWsdlFilePath;
|
||||
}
|
||||
|
||||
private function getHttpHeadersBySoapVersion(SoapRequest $soapRequest)
|
||||
{
|
||||
if ($soapRequest->getVersion() === SOAP_1_1) {
|
||||
|
||||
return [
|
||||
'Content-Type: ' . $soapRequest->getContentType(),
|
||||
'SOAPAction: "' . $soapRequest->getAction() . '"',
|
||||
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'Content-Type: ' . $soapRequest->getContentType() . '; action="' . $soapRequest->getAction() . '"',
|
||||
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
||||
];
|
||||
}
|
||||
|
||||
private function getAttachmentFilters()
|
||||
{
|
||||
$filters = [];
|
||||
@ -277,7 +294,6 @@ class SoapClient extends \SoapClient
|
||||
array $soapAttachments = []
|
||||
) {
|
||||
if ($this->soapClientOptions->getTrace() === true) {
|
||||
|
||||
return SoapResponseFactory::createWithTracingData(
|
||||
$soapRequest,
|
||||
$curlResponse->getResponseBody(),
|
||||
@ -288,10 +304,8 @@ class SoapClient extends \SoapClient
|
||||
}
|
||||
|
||||
return SoapResponseFactory::create(
|
||||
$soapRequest,
|
||||
$curlResponse->getResponseBody(),
|
||||
$soapRequest->getLocation(),
|
||||
$soapRequest->getAction(),
|
||||
$soapRequest->getVersion(),
|
||||
$curlResponse->getHttpResponseContentType(),
|
||||
$soapAttachments
|
||||
);
|
||||
@ -320,68 +334,43 @@ class SoapClient extends \SoapClient
|
||||
);
|
||||
}
|
||||
|
||||
private function decorateNativeSoapFault(SoapFault $nativePhpSoapFault)
|
||||
private function decorateNativeSoapFaultWithSoapResponseTracingData(SoapFault $nativePhpSoapFault)
|
||||
{
|
||||
$soapResponse = $this->getSoapResponseFromStorage();
|
||||
if ($soapResponse instanceof SoapResponse) {
|
||||
$soapFault = $this->throwSoapFaultByTracing(
|
||||
SoapFaultPrefixEnum::PREFIX_PHP . '-' . $nativePhpSoapFault->getCode(),
|
||||
$nativePhpSoapFault->getMessage(),
|
||||
$this->getSoapResponseTracingDataFromNativeSoapFault(
|
||||
$nativePhpSoapFault,
|
||||
new SoapResponseTracingData(
|
||||
'Content-Type: '.$soapResponse->getRequest()->getContentType(),
|
||||
$soapResponse->getRequest()->getContent(),
|
||||
'Content-Type: '.$soapResponse->getContentType(),
|
||||
$soapResponse->getResponseContent()
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$soapFault = $this->throwSoapFaultByTracing(
|
||||
$nativePhpSoapFault->faultcode,
|
||||
$nativePhpSoapFault->getMessage(),
|
||||
$this->getSoapResponseTracingDataFromNativeSoapFault(
|
||||
$nativePhpSoapFault,
|
||||
new SoapResponseTracingData(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $soapFault;
|
||||
return $this->throwSoapFaultByTracing(
|
||||
$nativePhpSoapFault->faultcode,
|
||||
$nativePhpSoapFault->getMessage(),
|
||||
$this->getSoapResponseTracingDataFromNativeSoapFaultOrStorage($nativePhpSoapFault)
|
||||
);
|
||||
}
|
||||
|
||||
private function getSoapResponseTracingDataFromNativeSoapFault(
|
||||
SoapFault $nativePhpSoapFault,
|
||||
SoapResponseTracingData $defaultSoapFaultTracingData
|
||||
) {
|
||||
private function getSoapResponseTracingDataFromNativeSoapFaultOrStorage(SoapFault $nativePhpSoapFault)
|
||||
{
|
||||
if ($nativePhpSoapFault instanceof SoapFaultWithTracingData) {
|
||||
|
||||
return $nativePhpSoapFault->getSoapResponseTracingData();
|
||||
}
|
||||
|
||||
return $defaultSoapFaultTracingData;
|
||||
return $this->getSoapResponseTracingDataFromRequestStorage();
|
||||
}
|
||||
|
||||
private function getHttpHeadersBySoapVersion(SoapRequest $soapRequest)
|
||||
private function getSoapResponseTracingDataFromRequestStorage()
|
||||
{
|
||||
if ($soapRequest->getVersion() === SOAP_1_1) {
|
||||
$lastResponseHeaders = $lastResponse = $lastRequestHeaders = $lastRequest = null;
|
||||
$soapResponse = $this->getSoapResponseFromStorage();
|
||||
if ($soapResponse instanceof SoapResponse) {
|
||||
$lastResponseHeaders = 'Content-Type: ' . $soapResponse->getContentType();
|
||||
$lastResponse = $soapResponse->getResponseContent();
|
||||
|
||||
return [
|
||||
'Content-Type: ' . $soapRequest->getContentType(),
|
||||
'SOAPAction: "' . $soapRequest->getAction() . '"',
|
||||
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
||||
];
|
||||
if ($soapResponse->hasRequest() === true) {
|
||||
$lastRequestHeaders = 'Content-Type: ' . $soapResponse->getRequest()->getContentType();
|
||||
$lastRequest = $soapResponse->getRequest()->getContent();
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'Content-Type: ' . $soapRequest->getContentType() . '; action="' . $soapRequest->getAction() . '"',
|
||||
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
||||
];
|
||||
return new SoapResponseTracingData(
|
||||
$lastRequestHeaders,
|
||||
$lastRequest,
|
||||
$lastResponseHeaders,
|
||||
$lastResponse
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class SoapClientOptionsBuilder
|
||||
public static function createWithDefaults()
|
||||
{
|
||||
return new SoapClientOptions(
|
||||
SoapClientOptions::SOAP_CLIENT_TRACE_OFF,
|
||||
SoapClientOptions::SOAP_CLIENT_TRACE_ON,
|
||||
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
|
||||
CurlOptions::DEFAULT_USER_AGENT,
|
||||
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE
|
||||
|
@ -44,6 +44,11 @@ class SoapResponse extends CommonSoapResponse
|
||||
$this->tracingData = $tracingData;
|
||||
}
|
||||
|
||||
public function hasRequest()
|
||||
{
|
||||
return $this->request !== null;
|
||||
}
|
||||
|
||||
public function setRequest(SoapRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
|
@ -27,27 +27,24 @@ class SoapResponseFactory
|
||||
/**
|
||||
* Factory method for SoapClient\SoapResponse.
|
||||
*
|
||||
* @param SoapRequest $soapRequest related request object
|
||||
* @param string $content Content
|
||||
* @param string $location Location
|
||||
* @param string $action SOAP action
|
||||
* @param string $version SOAP version
|
||||
* @param string $contentType Content type header
|
||||
* @param SoapAttachment[] $attachments SOAP attachments
|
||||
* @return SoapResponse
|
||||
*/
|
||||
public static function create(
|
||||
SoapRequest $soapRequest,
|
||||
$content,
|
||||
$location,
|
||||
$action,
|
||||
$version,
|
||||
$contentType,
|
||||
array $attachments = []
|
||||
) {
|
||||
$response = new SoapResponse();
|
||||
$response->setRequest($soapRequest);
|
||||
$response->setContent($content);
|
||||
$response->setLocation($location);
|
||||
$response->setAction($action);
|
||||
$response->setVersion($version);
|
||||
$response->setLocation($soapRequest->getLocation());
|
||||
$response->setAction($soapRequest->getAction());
|
||||
$response->setVersion($soapRequest->getVersion());
|
||||
$response->setContentType($contentType);
|
||||
if (count($attachments) > 0) {
|
||||
$response->setAttachments(
|
||||
@ -82,9 +79,7 @@ class SoapResponseFactory
|
||||
$response->setAction($soapRequest->getAction());
|
||||
$response->setVersion($soapRequest->getVersion());
|
||||
$response->setContentType($contentType);
|
||||
if ($tracingData !== null) {
|
||||
$response->setTracingData($tracingData);
|
||||
}
|
||||
$response->setTracingData($tracingData);
|
||||
if (count($attachments) > 0) {
|
||||
$response->setAttachments(
|
||||
PartFactory::createAttachmentParts($attachments)
|
||||
|
Reference in New Issue
Block a user