Skip to content

Commit

Permalink
fix: add withXMLAttributes param
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Filatov committed Jul 27, 2023
1 parent 0055c0e commit ed4fc0a
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/Requests/SoapRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,34 @@ trait SoapRequest
/**
* @return stdClass
*/
public function request(string $method, array $requestBody, bool $convertToSoap = true)
public function request(string $method, array $requestBody, bool $withXMLAttributes = false, bool $convertToSoap = true)
{
try {
$response = $this->soapClient->$method($convertToSoap ? $this->arrayToSoapVar($requestBody) : $requestBody);

RequestEvent::dispatch(
property_exists($this->soapClient, '__last_request') ? $this->soapClient->__last_request : '',
property_exists($this->soapClient, '__last_response') ? $this->soapClient->__last_response : '',
$this->soapClient->__getLastRequest() ?? '',
$this->soapClient->__getLastResponse() ?? '',
true
);

if (config('vmware-php-client.enable_logs')) {
Log::info(
'SOAP REQUEST SUCCESS:'.
"\nSOAP method: ".$method.
property_exists($this->soapClient, '__last_request')
? "\nSOAP request start***".$this->soapClient->__last_request.'***SOAP request end'
$this->soapClient->__getLastRequest()
? "\nSOAP request start***".$this->soapClient->__getLastRequest().'***SOAP request end'
: ''
);
}

return $response;
return ($withXMLAttributes)
? $this->parseXMLResponse($this->soapClient->__getLastResponse())
: $response;
} catch (\Exception $exception) {
RequestEvent::dispatch(
property_exists($this->soapClient, '__last_request') ? $this->soapClient->__last_request : '',
property_exists($this->soapClient, '__last_response') ? $this->soapClient->__last_response : '',
$this->soapClient->__getLastRequest() ?? '',
$this->soapClient->__getLastResponse() ?? '',
false
);

Expand All @@ -66,21 +68,21 @@ public function request(string $method, array $requestBody, bool $convertToSoap
]);
$this->soapClient->__setCookie('vmware_soap_session', $sessionInfo['vmware_soap_session']);

return $this->request($method, $requestBody, $convertToSoap);
return $this->request($method, $requestBody, $withXMLAttributes, $convertToSoap);
}
}

$message = "SOAP REQUEST FAILED:\nMessage: ".$exception->getMessage().
"\nSOAP method: ".$method.
(
property_exists($this->soapClient, '__last_request')
? "\nSOAP request start***".$this->soapClient->__last_request.'***SOAP request end'
"\nSOAP method: ".$method.
(
$this->soapClient->__getLastRequest()
? "\nSOAP request start***".$this->soapClient->__getLastRequest().'***SOAP request end'
: ''
).(
property_exists($this->soapClient, '__last_response')
? "\nSOAP response start***: ".$this->soapClient->__last_response.'***SOAP response end'
).(
$this->soapClient->__getLastResponse()
? "\nSOAP response start***: ".$this->soapClient->__getLastResponse().'***SOAP response end'
: ''
);
);
// "\nTrace: ".json_encode($exception->getTrace());

Log::error($message);
Expand Down

0 comments on commit ed4fc0a

Please sign in to comment.