1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Surge\LaravelSalesforce; |
4
|
|
|
|
5
|
|
|
use Event; |
6
|
|
|
use Surge\LaravelSalesforce\Objects\BaseObject; |
7
|
|
|
|
8
|
|
|
class Salesforce |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $objName; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var SalesforceAuth |
17
|
|
|
*/ |
18
|
|
|
private $auth; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Salesforce constructor. |
22
|
|
|
* |
23
|
|
|
* @param $client |
24
|
|
|
* @param SalesforceAuth $auth |
25
|
|
|
*/ |
26
|
|
|
public function __construct($client, SalesforceAuth $auth) |
27
|
|
|
{ |
28
|
|
|
$this->client = $client; |
|
|
|
|
29
|
|
|
$this->auth = $auth; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function __call($method, $args) |
34
|
|
|
{ |
35
|
|
|
if (0 === strpos($method, 'create')) { |
36
|
|
|
return $this->callCreateOnObject($method, $args); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if (0 === strpos($method, 'update')) { |
40
|
|
|
return $this->callUpdateOnObject($method, $args); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if (0 === strpos($method, 'delete')) { |
44
|
|
|
return $this->callDeleteOnObject($method, $args); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (0 === strpos($method, 'get')) { |
48
|
|
|
return $this->callGetOnObject($method, $args); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return ''; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
private function callCreateOnObject($method, $args) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$type = substr($method, 6); |
57
|
|
|
$class = '\\Surge\\LaravelSalesforce\\Objects\\'.$type; |
58
|
|
|
|
59
|
|
|
if (class_exists($class)) { |
60
|
|
|
return (new $class())->create($args[0]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return (new BaseObject())->create($type, $args[0]); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
private function callUpdateOnObject($method, $args) |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$type = substr($method, 6); |
69
|
|
|
$class = '\\Surge\\LaravelSalesforce\\Objects\\'.$type; |
70
|
|
|
|
71
|
|
|
if (class_exists($class)) { |
72
|
|
|
return (new $class())->update($args[0]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return (new BaseObject())->update($type, $args[0]); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
View Code Duplication |
private function callDeleteOnObject($method, $args) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$type = substr($method, 6); |
81
|
|
|
$class = '\\Surge\\LaravelSalesforce\\Objects\\'.$type; |
82
|
|
|
|
83
|
|
|
if (class_exists($class)) { |
84
|
|
|
return (new $class())->delete($args[0]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return (new BaseObject())->delete($type, $args[0]); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
View Code Duplication |
private function callGetOnObject($method, $args) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$type = substr($method, 3); |
93
|
|
|
$class = '\\Surge\\LaravelSalesforce\\Objects\\'.$type; |
94
|
|
|
|
95
|
|
|
if (class_exists($class)) { |
96
|
|
|
return (new $class())->record($args[0]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return (new BaseObject())->record($type, $args[0]); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Run report. |
104
|
|
|
* |
105
|
|
|
* @param $params |
106
|
|
|
* |
107
|
|
|
* @return mixed |
108
|
|
|
*/ |
109
|
|
|
public function runReport($params) |
110
|
|
|
{ |
111
|
|
|
return $this->sendRequest( |
|
|
|
|
112
|
|
|
'GET', |
113
|
|
|
'/analytics/reports/'.$params['id'], |
114
|
|
|
['query' => ['includeDetails' => $params['includeDetails']]], |
115
|
|
|
false |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: