From 6c2a2395d776f84be9187871e1b3048f9be0a991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=AB=20Snaterse?= Date: Fri, 17 Jun 2016 17:14:59 +0200 Subject: [PATCH] Makes SalesForce support PHP7.0 --- soapclient/SforceEnterpriseClient.php | 52 ++++++++++++++------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/soapclient/SforceEnterpriseClient.php b/soapclient/SforceEnterpriseClient.php index 3aaa976..bc30758 100644 --- a/soapclient/SforceEnterpriseClient.php +++ b/soapclient/SforceEnterpriseClient.php @@ -50,7 +50,8 @@ function SforceEnterpriseClient() { * @return SaveResult */ public function create($sObjects, $type) { - foreach ($sObjects as &$sObject) { + $arg = []; + foreach ($sObjects as $sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) { @@ -59,16 +60,15 @@ public function create($sObjects, $type) { } } // ------ - - $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); + $soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2) if($xmlStr != '') { - $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); - } - // ------ + $soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); + } + // ------ + $arg[] = $soapObject; } - $arg = $sObjects; return parent::_create(new SoapParam($arg, "sObjects")); } @@ -81,10 +81,11 @@ public function create($sObjects, $type) { * @return UpdateResult */ public function update($sObjects, $type, $assignment_header = NULL, $mru_header = NULL) { + $arg = new stdClass; + $arg->sObjects = []; + foreach ($sObjects as $sObject) { - foreach ($sObjects as &$sObject) { - - // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) + // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) { foreach($sObject->fieldsToNull as $fieldToNull) { @@ -92,17 +93,17 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header } } // ------ - - $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); - - // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2) + + $soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); + + // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2) if($xmlStr != '') { - $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); + $soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } // ------ + $arg->sObjects[] = $soapObject; } - $arg = new stdClass; - $arg->sObjects = $sObjects; + return parent::_update($arg); } @@ -119,8 +120,9 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header */ public function upsert($ext_Id, $sObjects, $type = 'Contact') { $arg = new stdClass; + $arg->sObjects = []; $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); - foreach ($sObjects as &$sObject) { + foreach ($sObjects as $sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) { @@ -129,16 +131,17 @@ public function upsert($ext_Id, $sObjects, $type = 'Contact') { } } // ------ - - $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); + + $soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2) if($xmlStr != '') { - $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); - } + $soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); + } // ------ + $arg->sObjects[] = $soapObject; } - $arg->sObjects = $sObjects; + return parent::_upsert($arg); } @@ -155,5 +158,4 @@ public function merge($mergeRequest, $type) { $arg->request = new SoapVar($mergeRequest, SOAP_ENC_OBJECT, 'MergeRequest', $this->namespace); return parent::_merge($arg); } -} -?> +} \ No newline at end of file