From ed4fc0a68c6c676864f33533f9f7fad1bd39ff1e Mon Sep 17 00:00:00 2001 From: Dmitry Filatov Date: Thu, 27 Jul 2023 15:41:01 +0300 Subject: [PATCH 1/2] fix: add withXMLAttributes param --- src/Requests/SoapRequest.php | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Requests/SoapRequest.php b/src/Requests/SoapRequest.php index 1122a45..a4ef979 100644 --- a/src/Requests/SoapRequest.php +++ b/src/Requests/SoapRequest.php @@ -19,14 +19,14 @@ 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 ); @@ -34,17 +34,19 @@ public function request(string $method, array $requestBody, bool $convertToSoap 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 ); @@ -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); From d9afb25da74593fecedf2b95cab969b1b27ded0f Mon Sep 17 00:00:00 2001 From: Dmitry Filatov Date: Mon, 7 Aug 2023 10:11:34 +0300 Subject: [PATCH 2/2] fix: check prop exists --- src/Traits/Soap/SoapImportApis.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Traits/Soap/SoapImportApis.php b/src/Traits/Soap/SoapImportApis.php index 14eae99..f659e78 100644 --- a/src/Traits/Soap/SoapImportApis.php +++ b/src/Traits/Soap/SoapImportApis.php @@ -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 ?? ''; + } } }