Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
a76526a5b6 | |||
baf32c1350 | |||
5c0bf914e3 | |||
01d10b89fd |
@ -62,7 +62,7 @@ class Curl
|
|||||||
curl_setopt_array($curlSession, [
|
curl_setopt_array($curlSession, [
|
||||||
CURLOPT_ENCODING => '',
|
CURLOPT_ENCODING => '',
|
||||||
CURLOPT_SSL_VERIFYPEER => false,
|
CURLOPT_SSL_VERIFYPEER => false,
|
||||||
CURLOPT_FAILONERROR => true,
|
CURLOPT_FAILONERROR => false,
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||||
CURLOPT_HEADER => true,
|
CURLOPT_HEADER => true,
|
||||||
@ -147,6 +147,8 @@ class Curl
|
|||||||
$headerSize = curl_getinfo($curlSession, CURLINFO_HEADER_SIZE);
|
$headerSize = curl_getinfo($curlSession, CURLINFO_HEADER_SIZE);
|
||||||
$httpResponseCode = curl_getinfo($curlSession, CURLINFO_HTTP_CODE);
|
$httpResponseCode = curl_getinfo($curlSession, CURLINFO_HTTP_CODE);
|
||||||
$httpResponseContentType = curl_getinfo($curlSession, CURLINFO_CONTENT_TYPE);;
|
$httpResponseContentType = curl_getinfo($curlSession, CURLINFO_CONTENT_TYPE);;
|
||||||
|
$responseBody = substr($executeSoapCallResponse, $headerSize);
|
||||||
|
$responseHeaders = substr($executeSoapCallResponse, 0, $headerSize);
|
||||||
preg_match('/HTTP\/(1\.[0-1]+) ([0-9]{3}) (.*)/', $executeSoapCallResponse, $httpResponseMessages);
|
preg_match('/HTTP\/(1\.[0-1]+) ([0-9]{3}) (.*)/', $executeSoapCallResponse, $httpResponseMessages);
|
||||||
$httpResponseMessage = trim(array_pop($httpResponseMessages));
|
$httpResponseMessage = trim(array_pop($httpResponseMessages));
|
||||||
$curlErrorMessage = sprintf(
|
$curlErrorMessage = sprintf(
|
||||||
@ -156,7 +158,7 @@ class Curl
|
|||||||
$location
|
$location
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($executeSoapCallResponse === false) {
|
if (!is_integer($httpResponseCode) || $httpResponseCode >= 400) {
|
||||||
|
|
||||||
return new CurlResponse(
|
return new CurlResponse(
|
||||||
$httpRequestHeadersAsString,
|
$httpRequestHeadersAsString,
|
||||||
@ -164,6 +166,8 @@ class Curl
|
|||||||
$httpResponseMessage,
|
$httpResponseMessage,
|
||||||
$httpResponseContentType,
|
$httpResponseContentType,
|
||||||
self::CURL_FAILED,
|
self::CURL_FAILED,
|
||||||
|
$responseHeaders,
|
||||||
|
$responseBody,
|
||||||
$curlErrorMessage
|
$curlErrorMessage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -174,9 +178,8 @@ class Curl
|
|||||||
$httpResponseMessage,
|
$httpResponseMessage,
|
||||||
$httpResponseContentType,
|
$httpResponseContentType,
|
||||||
self::CURL_SUCCESS,
|
self::CURL_SUCCESS,
|
||||||
null,
|
$responseHeaders,
|
||||||
substr($executeSoapCallResponse, 0, $headerSize),
|
$responseBody
|
||||||
substr($executeSoapCallResponse, $headerSize)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use Exception;
|
|||||||
class CurlOptionsBuilder
|
class CurlOptionsBuilder
|
||||||
{
|
{
|
||||||
const DEFAULT_MAX_REDIRECTS = 10;
|
const DEFAULT_MAX_REDIRECTS = 10;
|
||||||
const DEFAULT_CONNECTION_TIMEOUT = 10;
|
const DEFAULT_CONNECTION_TIMEOUT = 120;
|
||||||
|
|
||||||
public static function buildDefault()
|
public static function buildDefault()
|
||||||
{
|
{
|
||||||
|
@ -19,9 +19,9 @@ class CurlResponse
|
|||||||
$httpResponseStatusMessage,
|
$httpResponseStatusMessage,
|
||||||
$httpResponseContentType,
|
$httpResponseContentType,
|
||||||
$curlStatus,
|
$curlStatus,
|
||||||
$curlErrorMessage = null,
|
$responseHeader,
|
||||||
$responseHeader = null,
|
$responseBody,
|
||||||
$responseBody = null
|
$curlErrorMessage = null
|
||||||
) {
|
) {
|
||||||
$this->httpRequestHeaders = $httpRequestHeaders;
|
$this->httpRequestHeaders = $httpRequestHeaders;
|
||||||
$this->httpResponseStatusCode = $httpResponseStatusCode;
|
$this->httpResponseStatusCode = $httpResponseStatusCode;
|
||||||
@ -78,21 +78,11 @@ class CurlResponse
|
|||||||
return $this->curlErrorMessage;
|
return $this->curlErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasResponseHeader()
|
|
||||||
{
|
|
||||||
return $this->responseHeader !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getResponseHeader()
|
public function getResponseHeader()
|
||||||
{
|
{
|
||||||
return $this->responseHeader;
|
return $this->responseHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasResponseBody()
|
|
||||||
{
|
|
||||||
return $this->responseBody !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getResponseBody()
|
public function getResponseBody()
|
||||||
{
|
{
|
||||||
return $this->responseBody;
|
return $this->responseBody;
|
||||||
|
@ -41,6 +41,10 @@ class SoapClient extends \SoapClient
|
|||||||
protected $soapClientOptions;
|
protected $soapClientOptions;
|
||||||
protected $soapOptions;
|
protected $soapOptions;
|
||||||
private $curl;
|
private $curl;
|
||||||
|
/** @var SoapAttachment[] */
|
||||||
|
private $soapAttachmentsOnRequestStorage;
|
||||||
|
/** @var SoapResponse */
|
||||||
|
private $soapResponseStorage;
|
||||||
|
|
||||||
public function __construct(SoapClientOptions $soapClientOptions, SoapOptions $soapOptions)
|
public function __construct(SoapClientOptions $soapClientOptions, SoapOptions $soapOptions)
|
||||||
{
|
{
|
||||||
@ -54,7 +58,8 @@ class SoapClient extends \SoapClient
|
|||||||
$wsdlPath = $this->loadWsdl(
|
$wsdlPath = $this->loadWsdl(
|
||||||
$this->curl,
|
$this->curl,
|
||||||
$soapOptions->getWsdlFile(),
|
$soapOptions->getWsdlFile(),
|
||||||
$soapOptions->getWsdlCacheType()
|
$soapOptions->getWsdlCacheType(),
|
||||||
|
false
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new SoapFault(
|
throw new SoapFault(
|
||||||
@ -88,9 +93,9 @@ class SoapClient extends \SoapClient
|
|||||||
* @param array|null $output_headers
|
* @param array|null $output_headers
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __soapCall($function_name, array $arguments, array $options = null, $input_headers = null, array &$output_headers = null)
|
public function __soapCall($function_name, $arguments, $options = null, $input_headers = null, &$output_headers = null)
|
||||||
{
|
{
|
||||||
return $this->soapCall($function_name, $arguments, $options, $input_headers, $output_headers)->getContent();
|
return $this->soapCall($function_name, $arguments, $options, $input_headers, $output_headers)->getResponseContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,17 +109,13 @@ class SoapClient extends \SoapClient
|
|||||||
*/
|
*/
|
||||||
public function soapCall($functionName, array $arguments, array $soapAttachments = [], array $options = null, $inputHeaders = null, array &$outputHeaders = null)
|
public function soapCall($functionName, array $arguments, array $soapAttachments = [], array $options = null, $inputHeaders = null, array &$outputHeaders = null)
|
||||||
{
|
{
|
||||||
ob_start();
|
$this->setSoapAttachmentsOnRequestToStorage($soapAttachments);
|
||||||
parent::__soapCall($functionName, $arguments, $options, $inputHeaders, $outputHeaders);
|
$soapResponseAsObject = parent::__soapCall($functionName, $arguments, $options, $inputHeaders, $outputHeaders);
|
||||||
$nativeSoapClientRequest = $this->mapNativeDataJsonToDto(ob_get_clean());
|
|
||||||
|
|
||||||
return $this->performSoapRequest(
|
$soapResponse = $this->getSoapResponseFromStorage();
|
||||||
$nativeSoapClientRequest->request,
|
$soapResponse->setResponseObject($soapResponseAsObject);
|
||||||
$nativeSoapClientRequest->location,
|
|
||||||
$nativeSoapClientRequest->action,
|
return $soapResponse;
|
||||||
$nativeSoapClientRequest->version,
|
|
||||||
$soapAttachments
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,34 +131,16 @@ class SoapClient extends \SoapClient
|
|||||||
*/
|
*/
|
||||||
public function __doRequest($request, $location, $action, $version, $oneWay = 0)
|
public function __doRequest($request, $location, $action, $version, $oneWay = 0)
|
||||||
{
|
{
|
||||||
$soapClientNativeDataTransferObject = new SoapClientNativeDataTransferObject(
|
$soapResponse = $this->performSoapRequest(
|
||||||
$request,
|
$request,
|
||||||
$location,
|
$location,
|
||||||
$action,
|
$action,
|
||||||
$version
|
$version,
|
||||||
|
$this->getSoapAttachmentsOnRequestFromStorage()
|
||||||
);
|
);
|
||||||
echo json_encode($soapClientNativeDataTransferObject);
|
$this->setSoapResponseToStorage($soapResponse);
|
||||||
|
|
||||||
return $request;
|
return $soapResponse->getResponseContent();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom request method to be able to modify the SOAP messages.
|
|
||||||
* $oneWay parameter is not used at the moment.
|
|
||||||
*
|
|
||||||
* @param mixed $request Request object
|
|
||||||
* @param string $location Location
|
|
||||||
* @param string $action SOAP action
|
|
||||||
* @param int $version SOAP version
|
|
||||||
* @param SoapAttachment[] $soapAttachments SOAP attachments array
|
|
||||||
*
|
|
||||||
* @return SoapResponse
|
|
||||||
*/
|
|
||||||
public function performSoapRequest($request, $location, $action, $version, array $soapAttachments = [])
|
|
||||||
{
|
|
||||||
$soapRequest = $this->createSoapRequest($location, $action, $version, $request, $soapAttachments);
|
|
||||||
|
|
||||||
return $this->performHttpSoapRequest($soapRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
@ -200,6 +183,25 @@ class SoapClient extends \SoapClient
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom request method to be able to modify the SOAP messages.
|
||||||
|
* $oneWay parameter is not used at the moment.
|
||||||
|
*
|
||||||
|
* @param mixed $request Request object
|
||||||
|
* @param string $location Location
|
||||||
|
* @param string $action SOAP action
|
||||||
|
* @param int $version SOAP version
|
||||||
|
* @param SoapAttachment[] $soapAttachments SOAP attachments array
|
||||||
|
*
|
||||||
|
* @return SoapResponse
|
||||||
|
*/
|
||||||
|
private function performSoapRequest($request, $location, $action, $version, array $soapAttachments = [])
|
||||||
|
{
|
||||||
|
$soapRequest = $this->createSoapRequest($location, $action, $version, $request, $soapAttachments);
|
||||||
|
|
||||||
|
return $this->performHttpSoapRequest($soapRequest);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $location Location
|
* @param string $location Location
|
||||||
* @param string $action SOAP action
|
* @param string $action SOAP action
|
||||||
@ -336,18 +338,6 @@ class SoapClient extends \SoapClient
|
|||||||
return $filters;
|
return $filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function mapNativeDataJsonToDto($nativeDataJson)
|
|
||||||
{
|
|
||||||
$nativeData = json_decode($nativeDataJson);
|
|
||||||
|
|
||||||
return new SoapClientNativeDataTransferObject(
|
|
||||||
$nativeData->request,
|
|
||||||
$nativeData->location,
|
|
||||||
$nativeData->action,
|
|
||||||
$nativeData->version
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function returnSoapResponseByTracing(
|
private function returnSoapResponseByTracing(
|
||||||
$isTracingEnabled,
|
$isTracingEnabled,
|
||||||
SoapRequest $soapRequest,
|
SoapRequest $soapRequest,
|
||||||
@ -405,4 +395,33 @@ class SoapClient extends \SoapClient
|
|||||||
throw new Exception('SoapClientOptions tracing disabled, turn on trace attribute');
|
throw new Exception('SoapClientOptions tracing disabled, turn on trace attribute');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function setSoapResponseToStorage(SoapResponse $soapResponseStorage)
|
||||||
|
{
|
||||||
|
$this->soapResponseStorage = $soapResponseStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SoapAttachment[] $soapAttachments
|
||||||
|
*/
|
||||||
|
private function setSoapAttachmentsOnRequestToStorage(array $soapAttachments)
|
||||||
|
{
|
||||||
|
$this->soapAttachmentsOnRequestStorage = $soapAttachments;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSoapAttachmentsOnRequestFromStorage()
|
||||||
|
{
|
||||||
|
$soapAttachmentsOnRequest = $this->soapAttachmentsOnRequestStorage;
|
||||||
|
$this->soapAttachmentsOnRequestStorage = null;
|
||||||
|
|
||||||
|
return $soapAttachmentsOnRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSoapResponseFromStorage()
|
||||||
|
{
|
||||||
|
$soapResponse = $this->soapResponseStorage;
|
||||||
|
$this->soapResponseStorage = null;
|
||||||
|
|
||||||
|
return $soapResponse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace BeSimple\SoapClient;
|
|
||||||
|
|
||||||
class SoapClientNativeDataTransferObject
|
|
||||||
{
|
|
||||||
public $request;
|
|
||||||
public $location;
|
|
||||||
public $action;
|
|
||||||
public $version;
|
|
||||||
|
|
||||||
public function __construct($request, $location, $action, $version)
|
|
||||||
{
|
|
||||||
$this->request = $request;
|
|
||||||
$this->location = $location;
|
|
||||||
$this->action = $action;
|
|
||||||
$this->version = $version;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,8 +6,23 @@ use BeSimple\SoapCommon\SoapResponse as CommonSoapResponse;
|
|||||||
|
|
||||||
class SoapResponse extends CommonSoapResponse
|
class SoapResponse extends CommonSoapResponse
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
protected $responseObject;
|
||||||
|
|
||||||
public function getResponseContent()
|
public function getResponseContent()
|
||||||
{
|
{
|
||||||
return $this->getContent();
|
return $this->getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getResponseObject()
|
||||||
|
{
|
||||||
|
return $this->responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResponseObject($responseObject)
|
||||||
|
{
|
||||||
|
$this->responseObject = $responseObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user