From 0fc71fe8ec1402ccc3d0f37ecc40df506cc7c7a7 Mon Sep 17 00:00:00 2001 From: Davis Peixoto Date: Mon, 31 Mar 2014 23:42:02 -0300 Subject: [PATCH] all methods with scope declaration, some formatting work --- .../AssignmentRuleHeader.php | 1 + .../ForceDotComToolkitForPhp/CallOptions.php | 2 +- .../ForceDotComToolkitForPhp/Email.php | 16 -- .../MassEmailMessage.php | 40 ++++ .../ForceDotComToolkitForPhp/QueryResult.php | 48 +++-- .../ForceDotComToolkitForPhp/SObject.php | 96 +++------ .../SforceBaseClient.php | 202 ++++++++++++------ .../SforceEnterpriseClient.php | 33 +-- .../SforceMetadataClient.php | 78 +++---- .../SforcePartnerClient.php | 38 ++-- .../SforceSearchResult.php | 6 +- .../SforceSoapClient.php | 11 +- .../SingleEmailMessage.php | 49 +++-- 13 files changed, 365 insertions(+), 255 deletions(-) create mode 100644 src/Davispeixoto/ForceDotComToolkitForPhp/MassEmailMessage.php diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/AssignmentRuleHeader.php b/src/Davispeixoto/ForceDotComToolkitForPhp/AssignmentRuleHeader.php index cfab728..0bdca22 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/AssignmentRuleHeader.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/AssignmentRuleHeader.php @@ -47,6 +47,7 @@ public function __construct($id = NULL, $flag = NULL) { if ($id != NULL) { $this->assignmentRuleId = $id; } + if ($flag != NULL) { $this->useDefaultRuleFlag = $flag; } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/CallOptions.php b/src/Davispeixoto/ForceDotComToolkitForPhp/CallOptions.php index 4496383..2f2ce83 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/CallOptions.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/CallOptions.php @@ -29,7 +29,7 @@ class CallOptions { public $client; public $defaultNamespace; - public function __construct($client, $defaultNamespace=NULL) { + public function __construct($client, $defaultNamespace = NULL) { $this->client = $client; $this->defaultNamespace = $defaultNamespace; } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/Email.php b/src/Davispeixoto/ForceDotComToolkitForPhp/Email.php index 063c706..b3d7ea1 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/Email.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/Email.php @@ -60,20 +60,4 @@ public function setSenderDisplayName($name) { $this->senderDisplayName = $name; } } - - - -class MassEmailMessage extends Email { - public function setTemplateId($templateId) { - $this->templateId = $templateId; - } - - public function setWhatIds($array) { - $this->whatIds = $array; - } - - public function setTargetObjectIds($array) { - $this->targetObjectIds = $array; - } -} ?> \ No newline at end of file diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/MassEmailMessage.php b/src/Davispeixoto/ForceDotComToolkitForPhp/MassEmailMessage.php new file mode 100644 index 0000000..9a73eeb --- /dev/null +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/MassEmailMessage.php @@ -0,0 +1,40 @@ +templateId = $templateId; + } + + public function setWhatIds($array) { + $this->whatIds = $array; + } + + public function setTargetObjectIds($array) { + $this->targetObjectIds = $array; + } +} +?> \ No newline at end of file diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/QueryResult.php b/src/Davispeixoto/ForceDotComToolkitForPhp/QueryResult.php index 79e3338..8101a83 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/QueryResult.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/QueryResult.php @@ -25,7 +25,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -class QueryResult implements Iterator{ +class QueryResult implements \Iterator { public $queryLocator; public $done; public $records; @@ -34,7 +34,8 @@ class QueryResult implements Iterator{ public $pointer; // Current iterator location private $sf; // SOAP Client - public function __construct($response) { + public function __construct($response) + { $this->queryLocator = $response->queryLocator; $this->done = $response->done; $this->size = $response->size; @@ -50,27 +51,47 @@ public function __construct($response) { if (is_array($response->records)) { foreach ($response->records as $record) { array_push($this->records, $record); - }; + } } else { array_push($this->records, $record); } } } } - - public function setSf(SforceBaseClient $sf) { $this->sf = $sf; } // Dependency Injection + + // Dependency Injection + public function setSf(SforceBaseClient $sf) + { + $this->sf = $sf; + } // Basic Iterator implementation functions - public function rewind() { $this->pointer = 0; } - public function next() { ++$this->pointer; } - public function key() { return $this->pointer; } - public function current() { return new SObject($this->records[$this->pointer]); } + public function rewind() { + $this->pointer = 0; + } + + public function next() { + ++$this->pointer; + } + + public function key() + { + return $this->pointer; + } + + public function current() + { + return new SObject($this->records[$this->pointer]); + } - public function valid() { + public function valid() + { while ($this->pointer >= count($this->records)) { // Pointer is larger than (current) result set; see if we can fetch more if ($this->done === false) { - if ($this->sf === false) throw new \Exception("Dependency not met!"); + if ($this->sf === false) { + throw new \Exception("Dependency not met!"); + } $response = $this->sf->queryMore($this->queryLocator); $this->records = array_merge($this->records, $response->records); // Append more results $this->done = $response->done; @@ -79,7 +100,10 @@ public function valid() { return false; // No more records to fetch } } - if (isset($this->records[$this->pointer])) return true; + + if (isset($this->records[$this->pointer])) { + return true; + } throw new \Exception("QueryResult has gaps in the record data?"); } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php index 34cd3d8..78e0e6e 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php @@ -30,7 +30,8 @@ class SObject { public $fields; // public $sobject; - public function __construct($response=NULL) { + public function __construct($response = NULL) + { if (!isset($response) && !$response) { return; } @@ -52,44 +53,30 @@ public function __construct($response=NULL) { if (isset($response->any)) { try { - //$this->fields = $this->convertFields($response->any); - // If ANY is an object, instantiate another SObject - if ($response->any instanceof stdClass) { + if ($response->any instanceof \stdClass) { if ($this->isSObject($response->any)) { $anArray = array(); $sobject = new SObject($response->any); $anArray[] = $sobject; $this->sobjects = $anArray; } else { - // this is for parent to child relationships $this->queryResult = new QueryResult($response->any); } - } else { - // If ANY is an array if (is_array($response->any)) { - // Loop through each and perform some action. $anArray = array(); - - // Modify the foreach to have $key=>$value - // Added on 28th April 2008 - foreach ($response->any as $key=>$item) { - if ($item instanceof stdClass) { + foreach ($response->any as $key => $item) { + if ($item instanceof \stdClass) { if ($this->isSObject($item)) { $sobject = new SObject($item); - // make an associative array instead of a numeric one $anArray[$key] = $sobject; } else { - // this is for parent to child relationships - //$this->queryResult = new QueryResult($item); if (!isset($this->queryResult)) { $this->queryResult = array(); } array_push($this->queryResult, new QueryResult($item)); } } else { - //$this->fields = $this->convertFields($item); - if (strpos($item, 'sf:') === false) { $currentXmlValue = sprintf('%s', $key, $item, $key); } else { @@ -105,44 +92,14 @@ public function __construct($response=NULL) { } if (isset($fieldsToConvert)) { - // If this line is commented, then the fields becomes a stdclass object and does not have the name variable - // In this case the foreach loop on line 252 runs successfuly $this->fields = $this->convertFields($fieldsToConvert); } if (sizeof($anArray) > 0) { - // To add more variables to the the top level sobject foreach ($anArray as $key=>$children_sobject) { $this->fields->$key = $children_sobject; } - //array_push($this->fields, $anArray); - // Uncommented on 28th April since all the sobjects have now been moved to the fields - //$this->sobjects = $anArray; } - - /* - $this->fields = $this->convertFields($response->any[0]); - if (isset($response->any[1]->records)) { - $anArray = array(); - if ($response->any[1]->size == 1) { - $records = array ( - $response->any[1]->records - ); - } else { - $records = $response->any[1]->records; - } - foreach ($records as $record) { - $sobject = new SObject($record); - array_push($anArray, $sobject); - } - $this->sobjects = $anArray; - } else { - $anArray = array(); - $sobject = new SObject($response->any[1]); - array_push($anArray, $sobject); - $this->sobjects = $anArray; - } - */ } else { $this->fields = $this->convertFields($response->any); } @@ -153,30 +110,36 @@ public function __construct($response=NULL) { } } - function __get($name) { return (isset($this->fields->$name))? $this->fields->$name : false; } - function __isset($name) { return isset($this->fields->$name); } + public function __get($name) + { + return (isset($this->fields->$name)) ? $this->fields->$name : false; + } + + public function __isset($name) + { + return isset($this->fields->$name); + } /** * Parse the "any" string from an sObject. First strip out the sf: and then * enclose string with . Load the string using * simplexml_load_string and return an array that can be traversed. */ - function convertFields($any) { + public function convertFields($any) + { $str = preg_replace('{sf:}', '', $any); $array = $this->xml2array(''.$str.'', 2); $xml = new \stdClass(); - if (!count($array['Object'])) + if (!count($array['Object'])) { return $xml; + } - foreach ($array['Object'] as $k=>$v) { + foreach ($array['Object'] as $k => $v) { $xml->$k = $v; } - //$new_string = ''.$new_string.''; - //$new_string = $new_string; - //$xml = simplexml_load_string($new_string); return $xml; } @@ -185,21 +148,25 @@ function convertFields($any) { * @param string $contents * @return array */ - function xml2array($contents, $get_attributes=1) { - if(!$contents) return array(); + public function xml2array($contents, $get_attributes = 1) + { + if (!$contents) { + return array(); + } if(!function_exists('xml_parser_create')) { - //print "'xml_parser_create()' function not found!"; return array('not found'); } - //Get the XML parser of PHP - PHP must have this module for the parser to work + $parser = xml_parser_create(); xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 ); xml_parse_into_struct( $parser, $contents, $xml_values ); xml_parser_free( $parser ); - if(!$xml_values) return;//Hmm... + if(!$xml_values) { + return; + } //Initializations $xml_array = array(); @@ -209,7 +176,6 @@ function xml2array($contents, $get_attributes=1) { $current = &$xml_array; - //Go through the tags. foreach($xml_values as $data) { unset($attributes,$value);//Remove existing values, or there will be trouble @@ -292,14 +258,16 @@ function xml2array($contents, $get_attributes=1) { /* * If the stdClass has a done, we know it is a QueryResult */ - function isQueryResult($param) { + public function isQueryResult($param) + { return isset($param->done); } /* * If the stdClass has a type, we know it is an SObject */ - function isSObject($param) { + public function isSObject($param) + { return isset($param->type); } } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceBaseClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceBaseClient.php index 3cb6788..a25448d 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceBaseClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceBaseClient.php @@ -56,11 +56,13 @@ class SforceBaseClient { protected $localeOptions; protected $packageVersionHeader; - protected function getSoapClient($wsdl, $options) { + protected function getSoapClient($wsdl, $options) + { return new \SoapClient($wsdl, $options); - } + } - public function getNamespace() { + public function getNamespace() + { return $this->namespace; } @@ -71,17 +73,18 @@ public function getNamespace() { // Otherwise, leave this value as 'phpClient/1.0'. protected $client_id; - public function printDebugInfo() { - echo "PHP Toolkit Version: $this->version\r\n"; + public function printDebugInfo() + { + echo 'PHP Toolkit Version: ' . $this->version . PHP_EOL; echo 'Current PHP version: ' . phpversion(); - echo "\r\n"; + echo PHP_EOL; echo 'SOAP enabled: '; if (extension_loaded('soap')) { echo 'True'; } else { echo 'False'; } - echo "\r\n"; + echo PHP_EOL; echo 'OpenSSL enabled: '; if (extension_loaded('openssl')) { echo 'True'; @@ -100,7 +103,8 @@ public function printDebugInfo() { * SoapClient constructor. @see * http://php.net/manual/en/soapclient.soapclient.php */ - public function createConnection($wsdl, $proxy=null, $soap_options=array()) { + public function createConnection($wsdl, $proxy = NULL, $soap_options=array()) + { $phpversion = substr(phpversion(), 0, strpos(phpversion(), '-')); $soapClientArray = array_merge(array ( @@ -126,12 +130,13 @@ public function createConnection($wsdl, $proxy=null, $soap_options=array()) { $soapClientArray = array_merge($soapClientArray, $proxySettings); } - $this->sforce = $this->getSoapClient($wsdl, $soapClientArray); + $this->sforce = $this->getSoapClient($wsdl, $soapClientArray); return $this->sforce; } - public function setCallOptions($header) { + public function setCallOptions($header) + { if ($header != NULL) { $this->callOptions = new \SoapHeader($this->namespace, 'CallOptions', array ( 'client' => $header->client, @@ -150,7 +155,8 @@ public function setCallOptions($header) { * * @return LoginResult */ - public function login($username, $password) { + public function login($username, $password) + { $this->sforce->__setSoapHeaders(NULL); if ($this->callOptions != NULL) { $this->sforce->__setSoapHeaders(array($this->callOptions)); @@ -173,7 +179,8 @@ public function login($username, $password) { * * @return LogoutResult */ - public function logout() { + public function logout() + { $this->setHeaders("logout"); $arg = new \stdClass(); return $this->sforce->logout(); @@ -184,7 +191,8 @@ public function logout() { * * @return invalidateSessionsResult */ - public function invalidateSessions() { + public function invalidateSessions() + { $this->setHeaders("invalidateSessions"); $arg = new \stdClass(); $this->logout(); @@ -195,7 +203,8 @@ public function invalidateSessions() { * Specifies the session ID returned from the login server after a successful * login. */ - protected function _setLoginHeader($loginResult) { + protected function _setLoginHeader($loginResult) + { $this->sessionId = $loginResult->sessionId; $this->setSessionHeader($this->sessionId); $serverURL = $loginResult->serverUrl; @@ -207,12 +216,14 @@ protected function _setLoginHeader($loginResult) { * * @param string $location Location */ - public function setEndpoint($location) { + public function setEndpoint($location) + { $this->location = $location; $this->sforce->__setLocation($location); } - private function setHeaders($call=NULL) { + private function setHeaders($call = NULL) + { $this->sforce->__setSoapHeaders(NULL); $header_array = array ( @@ -311,6 +322,7 @@ private function setHeaders($call=NULL) { 'process', 'query', 'retrieve', 'search', 'undelete', 'update', 'upsert', ); + if(in_array($call, $packageVersionHeaderCalls)) { $header = $this->packageVersionHeader; if ($header != NULL) { @@ -318,11 +330,11 @@ private function setHeaders($call=NULL) { } } - $this->sforce->__setSoapHeaders($header_array); } - public function setAssignmentRuleHeader($header) { + public function setAssignmentRuleHeader($header) + { if ($header != NULL) { $this->assignmentRuleHeader = new \SoapHeader($this->namespace, 'AssignmentRuleHeader', array ( 'assignmentRuleId' => $header->assignmentRuleId, @@ -333,7 +345,8 @@ public function setAssignmentRuleHeader($header) { } } - public function setEmailHeader($header) { + public function setEmailHeader($header) + { if ($header != NULL) { $this->emailHeader = new \SoapHeader($this->namespace, 'EmailHeader', array ( 'triggerAutoResponseEmail' => $header->triggerAutoResponseEmail, @@ -345,7 +358,8 @@ public function setEmailHeader($header) { } } - public function setLoginScopeHeader($header) { + public function setLoginScopeHeader($header) + { if ($header != NULL) { $this->loginScopeHeader = new \SoapHeader($this->namespace, 'LoginScopeHeader', array ( 'organizationId' => $header->organizationId, @@ -354,10 +368,10 @@ public function setLoginScopeHeader($header) { } else { $this->loginScopeHeader = NULL; } - //$this->setHeaders('login'); } - public function setMruHeader($header) { + public function setMruHeader($header) + { if ($header != NULL) { $this->mruHeader = new \SoapHeader($this->namespace, 'MruHeader', array ( 'updateMru' => $header->updateMruFlag @@ -367,7 +381,8 @@ public function setMruHeader($header) { } } - public function setSessionHeader($id) { + public function setSessionHeader($id) + { if ($id != NULL) { $this->sessionHeader = new \SoapHeader($this->namespace, 'SessionHeader', array ( 'sessionId' => $id @@ -379,7 +394,8 @@ public function setSessionHeader($id) { } } - public function setUserTerritoryDeleteHeader($header) { + public function setUserTerritoryDeleteHeader($header) + { if ($header != NULL) { $this->userTerritoryDeleteHeader = new \SoapHeader($this->namespace, 'UserTerritoryDeleteHeader ', array ( 'transferToUserId' => $header->transferToUserId @@ -389,7 +405,8 @@ public function setUserTerritoryDeleteHeader($header) { } } - public function setQueryOptions($header) { + public function setQueryOptions($header) + { if ($header != NULL) { $this->queryHeader = new \SoapHeader($this->namespace, 'QueryOptions', array ( 'batchSize' => $header->batchSize @@ -399,7 +416,8 @@ public function setQueryOptions($header) { } } - public function setAllowFieldTruncationHeader($header) { + public function setAllowFieldTruncationHeader($header) + { if ($header != NULL) { $this->allowFieldTruncationHeader = new \SoapHeader($this->namespace, 'AllowFieldTruncationHeader', array ( 'allowFieldTruncation' => $header->allowFieldTruncation @@ -410,7 +428,8 @@ public function setAllowFieldTruncationHeader($header) { } } - public function setLocaleOptions($header) { + public function setLocaleOptions($header) + { if ($header != NULL) { $this->localeOptions = new \SoapHeader($this->namespace, 'LocaleOptions', array ( @@ -425,7 +444,8 @@ public function setLocaleOptions($header) { /** * @param $header */ - public function setPackageVersionHeader($header) { + public function setPackageVersionHeader($header) + { if ($header != NULL) { $headerData = array('packageVersions' => array()); @@ -446,7 +466,8 @@ public function setPackageVersionHeader($header) { } } - public function getSessionId() { + public function getSessionId() + { return $this->sessionId; } @@ -454,35 +475,43 @@ public function getLocation() { return $this->location; } - public function getConnection() { + public function getConnection() + { return $this->sforce; } - public function getFunctions() { + public function getFunctions() + { return $this->sforce->__getFunctions(); } - public function getTypes() { + public function getTypes() + { return $this->sforce->__getTypes(); } - public function getLastRequest() { + public function getLastRequest() + { return $this->sforce->__getLastRequest(); } - public function getLastRequestHeaders() { + public function getLastRequestHeaders() + { return $this->sforce->__getLastRequestHeaders(); } - public function getLastResponse() { + public function getLastResponse() + { return $this->sforce->__getLastResponse(); } - public function getLastResponseHeaders() { + public function getLastResponseHeaders() + { return $this->sforce->__getLastResponseHeaders(); } - protected function _convertToAny($fields) { + protected function _convertToAny($fields) + { $anyString = ''; foreach ($fields as $key => $value) { $anyString = $anyString . '<' . $key . '>' . $value . ''; @@ -490,32 +519,38 @@ protected function _convertToAny($fields) { return $anyString; } - protected function _create($arg) { + protected function _create($arg) + { $this->setHeaders("create"); return $this->sforce->create($arg)->result; } - protected function _merge($arg) { + protected function _merge($arg) + { $this->setHeaders("merge"); return $this->sforce->merge($arg)->result; } - protected function _process($arg) { + protected function _process($arg) + { $this->setHeaders(); return $this->sforce->process($arg)->result; } - protected function _update($arg) { + protected function _update($arg) + { $this->setHeaders("update"); return $this->sforce->update($arg)->result; } - protected function _upsert($arg) { + protected function _upsert($arg) + { $this->setHeaders("upsert"); return $this->sforce->upsert($arg)->result; } - public function sendSingleEmail($request) { + public function sendSingleEmail($request) + { if (is_array($request)) { $messages = array(); foreach ($request as $r) { @@ -531,7 +566,8 @@ public function sendSingleEmail($request) { } } - public function sendMassEmail($request) { + public function sendMassEmail($request) + { if (is_array($request)) { $messages = array(); foreach ($request as $r) { @@ -547,7 +583,8 @@ public function sendMassEmail($request) { } } - protected function _sendEmail($arg) { + protected function _sendEmail($arg) + { $this->setHeaders(); return $this->sforce->sendEmail($arg)->result; } @@ -559,7 +596,8 @@ protected function _sendEmail($arg) { * * @return LeadConvertResult */ - public function convertLead($leadConverts) { + public function convertLead($leadConverts) + { $this->setHeaders("convertLead"); $arg = new \stdClass(); $arg->leadConverts = $leadConverts; @@ -572,7 +610,8 @@ public function convertLead($leadConverts) { * @param array $ids Array of fields * @return DeleteResult */ - public function delete($ids) { + public function delete($ids) + { $this->setHeaders("delete"); $arg = new \stdClass(); $arg->ids = $ids; @@ -585,7 +624,8 @@ public function delete($ids) { * @param array $ids Array of fields * @return DeleteResult */ - public function undelete($ids) { + public function undelete($ids) + { $this->setHeaders("undelete"); $arg = new \stdClass(); $arg->ids = $ids; @@ -598,7 +638,8 @@ public function undelete($ids) { * @param array $ids Array of fields * @return DeleteResult */ - public function emptyRecycleBin($ids) { + public function emptyRecycleBin($ids) + { $this->setHeaders(); $arg = new \stdClass(); $arg->ids = $ids; @@ -611,7 +652,8 @@ public function emptyRecycleBin($ids) { * @param array $processRequestArray * @return ProcessResult */ - public function processSubmitRequest($processRequestArray) { + public function processSubmitRequest($processRequestArray) + { if (is_array($processRequestArray)) { foreach ($processRequestArray as &$process) { $process = new \SoapVar($process, SOAP_ENC_OBJECT, 'ProcessSubmitRequest', $this->namespace); @@ -631,7 +673,8 @@ public function processSubmitRequest($processRequestArray) { * @param array $processRequestArray * @return ProcessResult */ - public function processWorkitemRequest($processRequestArray) { + public function processWorkitemRequest($processRequestArray) + { if (is_array($processRequestArray)) { foreach ($processRequestArray as &$process) { $process = new \SoapVar($process, SOAP_ENC_OBJECT, 'ProcessWorkitemRequest', $this->namespace); @@ -650,7 +693,8 @@ public function processWorkitemRequest($processRequestArray) { * * @return DescribeGlobalResult */ - public function describeGlobal() { + public function describeGlobal() + { $this->setHeaders("describeGlobal"); return $this->sforce->describeGlobal()->result; } @@ -665,12 +709,14 @@ public function describeGlobal() { * @param string Type Object Type * @return DescribeLayoutResult */ - public function describeLayout($type, array $recordTypeIds=null) { + public function describeLayout($type, array $recordTypeIds = NULL) + { $this->setHeaders("describeLayout"); $arg = new \stdClass(); $arg->sObjectType = new \SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); - if (isset($recordTypeIds) && count($recordTypeIds)) + if (isset($recordTypeIds) && count($recordTypeIds)) { $arg->recordTypeIds = $recordTypeIds; + } return $this->sforce->describeLayout($arg)->result; } @@ -681,7 +727,8 @@ public function describeLayout($type, array $recordTypeIds=null) { * @param string $type Object type * @return DescribsSObjectResult */ - public function describeSObject($type) { + public function describeSObject($type) + { $this->setHeaders("describeSObject"); $arg = new \stdClass(); $arg->sObjectType = new \SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); @@ -695,7 +742,8 @@ public function describeSObject($type) { * @param array $arrayOfTypes Array of object types. * @return DescribsSObjectResult */ - public function describeSObjects($arrayOfTypes) { + public function describeSObjects($arrayOfTypes) + { $this->setHeaders("describeSObjects"); return $this->sforce->describeSObjects($arrayOfTypes)->result; } @@ -707,7 +755,8 @@ public function describeSObjects($arrayOfTypes) { * * @return DescribeTabSetResult */ - public function describeTabs() { + public function describeTabs() + { $this->setHeaders("describeTabs"); return $this->sforce->describeTabs()->result; } @@ -719,7 +768,8 @@ public function describeTabs() { * @param string $sObjectType sObject Type * @return DescribeDataCategoryGroupResult */ - public function describeDataCategoryGroups($sObjectType) { + public function describeDataCategoryGroups($sObjectType) + { $this->setHeaders('describeDataCategoryGroups'); $arg = new \stdClass(); $arg->sObjectType = new \SoapVar($sObjectType, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); @@ -733,7 +783,8 @@ public function describeDataCategoryGroups($sObjectType) { * @param bool $topCategoriesOnly Object Type * @return DescribeLayoutResult */ - public function describeDataCategoryGroupStructures(array $pairs, $topCategoriesOnly) { + public function describeDataCategoryGroupStructures(array $pairs, $topCategoriesOnly) + { $this->setHeaders('describeDataCategoryGroupStructures'); $arg = new \stdClass(); $arg->pairs = $pairs; @@ -751,7 +802,8 @@ public function describeDataCategoryGroupStructures(array $pairs, $topCategories * @param date $endDate End Date * @return GetDeletedResult */ - public function getDeleted($type, $startDate, $endDate) { + public function getDeleted($type, $startDate, $endDate) + { $this->setHeaders("getDeleted"); $arg = new \stdClass(); $arg->sObjectType = new \SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); @@ -769,7 +821,8 @@ public function getDeleted($type, $startDate, $endDate) { * @param date $endDate End Date * @return GetUpdatedResult */ - public function getUpdated($type, $startDate, $endDate) { + public function getUpdated($type, $startDate, $endDate) + { $this->setHeaders("getUpdated"); $arg = new \stdClass(); $arg->sObjectType = new \SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); @@ -786,7 +839,8 @@ public function getUpdated($type, $startDate, $endDate) { * @param QueryOptions $queryOptions Batch size limit. OPTIONAL * @return QueryResult */ - public function query($query) { + public function query($query) + { $this->setHeaders("query"); $raw = $this->sforce->query(array ( 'queryString' => $query @@ -803,7 +857,8 @@ public function query($query) { * @param QueryOptions $queryOptions Batch size limit. OPTIONAL * @return QueryResult */ - public function queryMore($queryLocator) { + public function queryMore($queryLocator) + { $this->setHeaders("queryMore"); $arg = new \stdClass(); $arg->queryLocator = $queryLocator; @@ -820,7 +875,8 @@ public function queryMore($queryLocator) { * @param QueryOptions $queryOptions Batch size limit. OPTIONAL * @return QueryResult */ - public function queryAll($query, $queryOptions = NULL) { + public function queryAll($query, $queryOptions = NULL) + { $this->setHeaders("queryAll"); $raw = $this->sforce->queryAll(array ( 'queryString' => $query @@ -839,7 +895,8 @@ public function queryAll($query, $queryOptions = NULL) { * @param array $ids Array of one or more IDs of the objects to retrieve. * @return sObject[] */ - public function retrieve($fieldList, $sObjectType, $ids) { + public function retrieve($fieldList, $sObjectType, $ids) + { $this->setHeaders("retrieve"); $arg = new \stdClass(); $arg->fieldList = $fieldList; @@ -854,7 +911,8 @@ public function retrieve($fieldList, $sObjectType, $ids) { * @param string $searchString Search string that specifies the text expression to search for. * @return SearchResult */ - public function search($searchString) { + public function search($searchString) + { $this->setHeaders("search"); $arg = new \stdClass(); $arg->searchString = new \SoapVar($searchString, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); @@ -866,12 +924,14 @@ public function search($searchString) { * * @return timestamp */ - public function getServerTimestamp() { + public function getServerTimestamp() + { $this->setHeaders("getServerTimestamp"); return $this->sforce->getServerTimestamp()->result; } - public function getUserInfo() { + public function getUserInfo() + { $this->setHeaders("getUserInfo"); return $this->sforce->getUserInfo()->result; } @@ -882,7 +942,8 @@ public function getUserInfo() { * @param string $userId ID of the User. * @param string $password New password */ - public function setPassword($userId, $password) { + public function setPassword($userId, $password) + { $this->setHeaders("setPassword"); $arg = new \stdClass(); $arg->userId = new \SoapVar($userId, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); @@ -896,7 +957,8 @@ public function setPassword($userId, $password) { * @param string $userId Id of the User * @return password */ - public function resetPassword($userId) { + public function resetPassword($userId) + { $this->setHeaders("resetPassword"); $arg = new \stdClass(); $arg->userId = new \SoapVar($userId, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceEnterpriseClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceEnterpriseClient.php index 9d7e641..bff2137 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceEnterpriseClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceEnterpriseClient.php @@ -37,7 +37,8 @@ class SforceEnterpriseClient extends SforceBaseClient { const ENTERPRISE_NAMESPACE = 'urn:enterprise.soap.sforce.com'; - public function __construct() { + public function __construct() + { $this->namespace = self::ENTERPRISE_NAMESPACE; } @@ -48,7 +49,8 @@ public function __construct() { * @param MruHeader $mru_header is optional. Defaults to NULL * @return SaveResult */ - public function create($sObjects, $type) { + public function create($sObjects, $type) + { foreach ($sObjects as &$sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; @@ -57,18 +59,17 @@ public function create($sObjects, $type) { $xmlStr .= '' . $fieldToNull . ''; } } - // ------ - $sObject = new \SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); + $sObject = 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); } - // ------ } + $arg = $sObjects; - + return parent::_create(new \SoapParam($arg, "sObjects")); } @@ -79,10 +80,9 @@ public function create($sObjects, $type) { * @param MruHeader $mru_header is optional. Defaults to NULL * @return UpdateResult */ - public function update($sObjects, $type, $assignment_header = NULL, $mru_header = NULL) { - + public function update($sObjects, $type, $assignment_header = NULL, $mru_header = NULL) + { foreach ($sObjects as &$sObject) { - // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) { @@ -90,7 +90,6 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header $xmlStr .= '' . $fieldToNull . ''; } } - // ------ $sObject = new \SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); @@ -98,8 +97,8 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header if($xmlStr != '') { $sObject->enc_value->fieldsToNull = new \SoapVar(new \SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } - // ------ } + $arg = new \stdClass; $arg->sObjects = $sObjects; return parent::_update($arg); @@ -116,9 +115,11 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header * @param string $type The type of objects being upserted. * @return UpsertResult */ - public function upsert($ext_Id, $sObjects, $type = 'Contact') { + public function upsert($ext_Id, $sObjects, $type = 'Contact') + { $arg = new \stdClass; $arg->externalIDFieldName = new \SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + foreach ($sObjects as &$sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) $xmlStr = ''; @@ -127,7 +128,6 @@ public function upsert($ext_Id, $sObjects, $type = 'Contact') { $xmlStr .= '' . $fieldToNull . ''; } } - // ------ $sObject = new \SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); @@ -135,8 +135,8 @@ public function upsert($ext_Id, $sObjects, $type = 'Contact') { if($xmlStr != '') { $sObject->enc_value->fieldsToNull = new \SoapVar(new \SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } - // ------ } + $arg->sObjects = $sObjects; return parent::_upsert($arg); } @@ -148,11 +148,12 @@ public function upsert($ext_Id, $sObjects, $type = 'Contact') { * @param String $type * @return unknown */ - public function merge($mergeRequest, $type) { + public function merge($mergeRequest, $type) + { $mergeRequest->masterRecord = new \SoapVar($mergeRequest->masterRecord, SOAP_ENC_OBJECT, $type, $this->namespace); $arg = new \stdClass; $arg->request = new \SoapVar($mergeRequest, SOAP_ENC_OBJECT, 'MergeRequest', $this->namespace); return parent::_merge($arg); } } -?> +?> \ No newline at end of file diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceMetadataClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceMetadataClient.php index 8b5117e..23195e2 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceMetadataClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceMetadataClient.php @@ -33,31 +33,29 @@ class SforceMetadataClient { protected $namespace = 'http://soap.sforce.com/2006/04/metadata'; - public function __construct($wsdl, $loginResult, $sforceConn) { - + public function __construct($wsdl, $loginResult, $sforceConn) + { $soapClientArray = null; - $phpversion = substr(phpversion(), 0, strpos(phpversion(), '-')); -// if (phpversion() > '5.1.2') { - if ($phpversion > '5.1.2') { + $phpversion = substr(phpversion(), 0, strpos(phpversion(), '-')); + if ($phpversion > '5.1.2') { $soapClientArray = array ( - 'user_agent' => 'salesforce-toolkit-php/'.$this->version, - 'encoding' => 'utf-8', - 'trace' => 1, - 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, - 'sessionId' => $loginResult->sessionId + 'user_agent' => 'salesforce-toolkit-php/'.$this->version, + 'encoding' => 'utf-8', + 'trace' => 1, + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, + 'sessionId' => $loginResult->sessionId ); } else { $soapClientArray = array ( - 'user_agent' => 'salesforce-toolkit-php/'.$this->version, - 'encoding' => 'utf-8', - 'trace' => 1, - 'sessionId' => $loginResult->sessionId + 'user_agent' => 'salesforce-toolkit-php/'.$this->version, + 'encoding' => 'utf-8', + 'trace' => 1, + 'sessionId' => $loginResult->sessionId ); } + $this->sforce = new \SoapClient($wsdl,$soapClientArray); - //$this->sforce->__setSoapHeaders($header_array); - $sessionVar = array( 'sessionId' => new \SoapVar($loginResult->sessionId, XSD_STRING) @@ -68,12 +66,12 @@ public function __construct($wsdl, $loginResult, $sforceConn) { $session_header = new \SoapHeader($this->namespace, 'SessionHeader', $headerBody, false); $header_array = array ( - $session_header + $session_header ); $this->sforce->__setSoapHeaders($header_array); - $this->sforce->__setLocation($loginResult->metadataServerUrl); + return $this->sforce; } @@ -81,7 +79,8 @@ public function __construct($wsdl, $loginResult, $sforceConn) { * Specifies the session ID returned from the login server after a successful * login. */ - protected function _setLoginHeader($loginResult) { + protected function _setLoginHeader($loginResult) + { $this->sessionId = $loginResult->sessionId; $this->setSessionHeader($this->sessionId); $serverURL = $loginResult->serverUrl; @@ -93,7 +92,8 @@ protected function _setLoginHeader($loginResult) { * * @param string $location Location */ - public function setEndpoint($location) { + public function setEndpoint($location) + { $this->location = $location; $this->sforce->__setLocation($location); } @@ -103,20 +103,22 @@ public function setEndpoint($location) { * * @param string $sessionId Session ID */ - public function setSessionHeader($sessionId) { + public function setSessionHeader($sessionId) + { $this->sforce->__setSoapHeaders(NULL); $session_header = new \SoapHeader($this->namespace, 'SessionHeader', array ( - 'sessionId' => $sessionId + 'sessionId' => $sessionId )); $this->sessionId = $sessionId; $header_array = array ( - $session_header + $session_header ); $this->_setClientId($header_array); $this->sforce->__setSoapHeaders($header_array); } - private function getObjtype($obj) { + private function getObjtype($obj) + { $classArray = explode('\\', get_class($obj)); $objtype = array_pop($classArray); if (strpos($objtype, 'Sforce', 0) === 0) { @@ -125,14 +127,16 @@ private function getObjtype($obj) { return $objtype; } - public function create($obj) { + public function create($obj) + { $encodedObj = new \stdClass(); $encodedObj->metadata = new \SoapVar($obj, SOAP_ENC_OBJECT, $this->getObjtype($obj), $this->namespace); return $this->sforce->create($encodedObj); } - public function update($obj) { + public function update($obj) + { $encodedObj = new \stdClass(); $encodedObj->UpdateMetadata = $obj; $encodedObj->UpdateMetadata->metadata = new \SoapVar($obj->metadata, SOAP_ENC_OBJECT, $this->getObjtype($obj->metadata), $this->namespace); @@ -140,35 +144,37 @@ public function update($obj) { return $this->sforce->update($encodedObj); } - public function delete($obj) { + public function delete($obj) + { $encodedObj = new \stdClass(); $encodedObj->metadata = new \SoapVar($obj, SOAP_ENC_OBJECT, $this->getObjtype($obj), $this->namespace); return $this->sforce->delete($encodedObj); } - public function checkStatus($ids) { + public function checkStatus($ids) + { return $this->sforce->checkStatus($ids); } - public function getLastRequest() { + public function getLastRequest() + { return $this->sforce->__getLastRequest(); } - public function getLastRequestHeaders() { + public function getLastRequestHeaders() + { return $this->sforce->__getLastRequestHeaders(); } - public function getLastResponse() { + public function getLastResponse() + { return $this->sforce->__getLastResponse(); } - public function getLastResponseHeaders() { + public function getLastResponseHeaders() + { return $this->sforce->__getLastResponseHeaders(); } - - } - - ?> diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforcePartnerClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforcePartnerClient.php index b46a2b7..57aaa5b 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforcePartnerClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforcePartnerClient.php @@ -33,13 +33,14 @@ class SforcePartnerClient extends SforceBaseClient { const PARTNER_NAMESPACE = 'urn:partner.soap.sforce.com'; - function SforcePartnerClient() { + function SforcePartnerClient() + { $this->namespace = self::PARTNER_NAMESPACE; } - protected function getSoapClient($wsdl, $options) { - // Workaround an issue in parsing OldValue and NewValue in histories - return new SforceSoapClient($wsdl, $options); + protected function getSoapClient($wsdl, $options) + { + return new SforceSoapClient($wsdl, $options); } /** @@ -47,7 +48,8 @@ protected function getSoapClient($wsdl, $options) { * @param array $sObjects Array of one or more sObjects (up to 200) to create. * @return SaveResult */ - public function create($sObjects) { + public function create($sObjects) + { $arg = new \stdClass; foreach ($sObjects as $sObject) { if (isset ($sObject->fields)) { @@ -65,7 +67,8 @@ public function create($sObjects) { * @param String $type * @return mixed */ - public function merge($mergeRequest) { + public function merge($mergeRequest) + { if (isset($mergeRequest->masterRecord)) { if (isset($mergeRequest->masterRecord->fields)) { $mergeRequest->masterRecord->any = $this->_convertToAny($mergeRequest->masterRecord->fields); @@ -80,7 +83,8 @@ public function merge($mergeRequest) { * * @param array $request */ - public function sendSingleEmail($request) { + public function sendSingleEmail($request) + { if (is_array($request)) { $messages = array(); foreach ($request as $r) { @@ -99,7 +103,8 @@ public function sendSingleEmail($request) { * * @param array $request */ - public function sendMassEmail($request) { + public function sendMassEmail($request) + { if (is_array($request)) { $messages = array(); foreach ($request as $r) { @@ -119,7 +124,8 @@ public function sendMassEmail($request) { * @param array sObjects Array of sObjects * @return UpdateResult */ - public function update($sObjects) { + public function update($sObjects) + { $arg = new \stdClass; foreach ($sObjects as $sObject) { if (isset($sObject->fields)) { @@ -140,8 +146,8 @@ public function update($sObjects) { * @param array $sObjects Array of sObjects * @return UpsertResult */ - public function upsert($ext_Id, $sObjects) { - // $this->_setSessionHeader(); + public function upsert($ext_Id, $sObjects) + { $arg = new \stdClass; $arg->externalIDFieldName = new \SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); foreach ($sObjects as $sObject) { @@ -159,7 +165,8 @@ public function upsert($ext_Id, $sObjects) { * @param array $ids * @return string */ - public function retrieve($fieldList, $sObjectType, $ids) { + public function retrieve($fieldList, $sObjectType, $ids) + { return $this->_retrieveResult(parent::retrieve($fieldList, $sObjectType, $ids)); } @@ -168,14 +175,15 @@ public function retrieve($fieldList, $sObjectType, $ids) { * @param mixed $response * @return array */ - private function _retrieveResult($response) { + private function _retrieveResult($response) + { $arr = array(); if(is_array($response)) { foreach($response as $r) { $sobject = new SObject($r); array_push($arr,$sobject); - }; - }else { + } + } else { $sobject = new SObject($response); array_push($arr, $sobject); } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceSearchResult.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceSearchResult.php index 553aba6..c9cc5f7 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceSearchResult.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceSearchResult.php @@ -28,8 +28,8 @@ class SforceSearchResult { public $searchRecords; - public function __construct($response) { - + public function __construct($response) + { if($response instanceof SforceSearchResult) { $this->searchRecords = $response->searchRecords; } else { @@ -39,7 +39,7 @@ public function __construct($response) { foreach ($response->searchRecords as $record) { $sobject = new SObject($record->record); array_push($this->searchRecords, $sobject); - }; + } } else { $sobject = new SObject($response->searchRecords->record); array_push($this->records, $sobject); diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceSoapClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceSoapClient.php index 9bc452d..6c64403 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceSoapClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceSoapClient.php @@ -35,10 +35,10 @@ // string content into the parsed output and loses the tag name. Removing the // xsi:type forces PHP SOAP to just leave the tags intact class SforceSoapClient extends SoapClient { - function __doRequest($request, $location, $action, $version, $one_way=0) { + public function __doRequest($request, $location, $action, $version, $one_way = 0) + { $response = parent::__doRequest($request, $location, $action, $version, $one_way); - // Quick check to only parse the XML here if we think we need to if (strpos($response, 'loadXML($response); $nodeList = $dom->getElementsByTagName('NewValue'); - foreach ($nodeList as $node) { + foreach ($nodeList as $key => $node) { $node->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'type'); } + $nodeList = $dom->getElementsByTagName('OldValue'); - foreach ($nodeList as $node) { + foreach ($nodeList as $key => $node) { $node->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'type'); } - + return $dom->saveXML(); } } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SingleEmailMessage.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SingleEmailMessage.php index 8bfb8a3..5142351 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SingleEmailMessage.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SingleEmailMessage.php @@ -25,55 +25,70 @@ * POSSIBILITY OF SUCH DAMAGE. */ class SingleEmailMessage extends Email { - public function __construct() {} - - - public function setBccAddresses($addresses) { + public $ccAddresses; + + public function __construct() + { + + } + + public function setBccAddresses($addresses) + { $this->bccAddresses = $addresses; } - public $ccAddresses; - - public function setCcAddresses($addresses) { + + public function setCcAddresses($addresses) + { $this->ccAddresses = $addresses; } - public function setCharset($charset) { + public function setCharset($charset) + { $this->charset = $charset; } - public function setHtmlBody($htmlBody) { + public function setHtmlBody($htmlBody) + { $this->htmlBody = $htmlBody; } - public function setOrgWideEmailAddressId($orgWideEmailAddressId) { + public function setOrgWideEmailAddressId($orgWideEmailAddressId) + { $this->orgWideEmailAddressId = $orgWideEmailAddressId; } - public function setPlainTextBody($plainTextBody) { + public function setPlainTextBody($plainTextBody) + { $this->plainTextBody = $plainTextBody; } - public function setTargetObjectId($targetObjectId) { + public function setTargetObjectId($targetObjectId) + { $this->targetObjectId = $targetObjectId; } - public function setTemplateId($templateId) { + public function setTemplateId($templateId) + { $this->templateId = $templateId; } - public function setToAddresses($array) { + public function setToAddresses($array) + { $this->toAddresses = $array; } - public function setWhatId($whatId) { + public function setWhatId($whatId) + { $this->whatId = $whatId; } - public function setFileAttachments($array) { + public function setFileAttachments($array) + { $this->fileAttachments = $array; } - public function setDocumentAttachments($array) { + public function setDocumentAttachments($array) + { $this->documentAttachments = $array; } } \ No newline at end of file