Skip to content

Commit

Permalink
all methods with scope declaration, some formatting work
Browse files Browse the repository at this point in the history
  • Loading branch information
davispeixoto committed Apr 1, 2014
1 parent 121047a commit 0fc71fe
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct($id = NULL, $flag = NULL) {
if ($id != NULL) {
$this->assignmentRuleId = $id;
}

if ($flag != NULL) {
$this->useDefaultRuleFlag = $flag;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Davispeixoto/ForceDotComToolkitForPhp/CallOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 0 additions & 16 deletions src/Davispeixoto/ForceDotComToolkitForPhp/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
?>
40 changes: 40 additions & 0 deletions src/Davispeixoto/ForceDotComToolkitForPhp/MassEmailMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php namespace Davispeixoto\ForceDotComToolkitForPhp;
/*
* Copyright (c) 2007, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
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;
}
}
?>
48 changes: 36 additions & 12 deletions src/Davispeixoto/ForceDotComToolkitForPhp/QueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

class QueryResult implements Iterator{
class QueryResult implements \Iterator {
public $queryLocator;
public $done;
public $records;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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?");
}
Expand Down
96 changes: 32 additions & 64 deletions src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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('<sf:%s>%s</sf:%s>', $key, $item, $key);
} else {
Expand All @@ -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);
}
Expand All @@ -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 <Object></Object>. 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('<Object xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'.$str.'</Object>', 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 = '<Object xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'.$new_string.'</Object>';
//$new_string = $new_string;
//$xml = simplexml_load_string($new_string);
return $xml;
}

Expand All @@ -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();
Expand All @@ -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

Expand Down Expand Up @@ -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);
}
}
Expand Down
Loading

0 comments on commit 0fc71fe

Please sign in to comment.