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

fix: add withXMLAttributes param #24

Merged
merged 3 commits into from
Aug 7, 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
20 changes: 11 additions & 9 deletions src/Requests/SoapRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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);
Expand All @@ -40,7 +40,9 @@ public function request(string $method, array $requestBody, bool $convertToSoap
);
}

return $response;
return ($withXMLAttributes)
? $this->parseXMLResponse($this->soapClient->__getLastResponse())
: $response;
} catch (\Exception $exception) {
RequestEvent::dispatch(
$this->soapClient->__getLastRequest() ?? '',
Expand All @@ -66,20 +68,20 @@ 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.
(
$this->soapClient->__getLastRequest()
? "\nSOAP request start***".$this->soapClient->__getLastRequest().'***SOAP request end'
: ''
$this->soapClient->__getLastRequest()
? "\nSOAP request start***".$this->soapClient->__getLastRequest().'***SOAP request end'
: ''
).(
$this->soapClient->__getLastResponse()
? "\nSOAP response start***: ".$this->soapClient->__getLastResponse().'***SOAP response end'
: ''
$this->soapClient->__getLastResponse()
? "\nSOAP response start***: ".$this->soapClient->__getLastResponse().'***SOAP response end'
: ''
);
// "\nTrace: ".json_encode($exception->getTrace());

Expand Down
15 changes: 10 additions & 5 deletions src/Traits/Soap/SoapImportApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ public function importVApp(string $resourcePoolId, $entityConfig, $instantiation
{
$extraConfig = [];
if (isset($configSpec->extraConfig)) {
foreach ($configSpec->extraConfig as $i => $config) {
$extraConfig[$i]['key'] = $config->key;
$extraConfig[$i]['value:string'] = isset($config->value->_value)
? $config->value->_value
: '';
// sometimes there is only one level of nesting
if (property_exists($configSpec->extraConfig, 'key')) {
$extraConfig['key'] = $configSpec->extraConfig->key;
$extraConfig['value:string'] = $configSpec->extraConfig->value->_value ?? '';
// but sometimes there are several
} else {
foreach ($configSpec->extraConfig as $i => $config) {
$extraConfig[$i]['key'] = $config->key;
$extraConfig[$i]['value:string'] = $config->value->_value ?? '';
}
}
}

Expand Down