Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite soap client accessor instead of properties #20

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 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'
: ''
).(
property_exists($this->soapClient, '__last_response')
? "\nSOAP response start***: ".$this->soapClient->__last_response.'***SOAP response end'
: ''
);
"\nSOAP method: ".$method.
(
$this->soapClient->__getLastRequest()
? "\nSOAP request start***".$this->soapClient->__getLastRequest().'***SOAP request 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