Skip to content

Commit

Permalink
feat: rewrite soap client accessor instead of properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tonkoshkurik committed Jun 22, 2023
1 parent 45cae2a commit c882a4f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
28 changes: 14 additions & 14 deletions src/Requests/SoapRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ public function request(string $method, array $requestBody, bool $convertToSoap
$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;
} 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 @@ -71,16 +71,16 @@ public function request(string $method, array $requestBody, bool $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
4 changes: 2 additions & 2 deletions src/Traits/Soap/SoapVmApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function getObjectInfo(string $objectId, string $objectType, string $path
} catch (\Exception $exception) {
Log::error(
"SOAP REQUEST FAILED:\nMessage: ".$exception->getMessage().
"\nSOAP request: ".$this->soapClient->__last_request.
"\nSOAP response: ".$this->soapClient->__last_response ?? ''
"\nSOAP request: ".($this->soapClient->__getLastRequest() ?? '').
"\nSOAP response: ".($this->soapClient->__getLastResponse() ?? '')
);

if (array_keys(json_decode(json_encode($exception->detail), true))[0] === 'ManagedObjectNotFoundFault') {
Expand Down
6 changes: 3 additions & 3 deletions src/VmWareClientInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ private function createSoapSession(): void
];
$this->soapClient->Login($loginMessage);

if (isset($this->soapClient->_cookies)) {
$soapSessionToken = $this->soapClient->_cookies['vmware_soap_session'][0];
if (array_key_exists('vmware_soap_session', $this->soapClient->__getCookies())) {
$soapSessionToken = $this->soapClient->__getCookies()['vmware_soap_session'][0];
} else {
$responseHeaders = $this->soapClient->__last_response_headers;
$responseHeaders = $this->soapClient->__getLastResponseHeaders();

$string = strstr($responseHeaders, 'vmware_soap_session');
$string = strstr($string, '"');
Expand Down

0 comments on commit c882a4f

Please sign in to comment.