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
|
|
|
* @param stirng $method |
34
|
|
|
* @param array $args |
35
|
|
|
* @return bool|mixed|string |
36
|
|
|
*/ |
37
|
|
|
public function __call($method, $args) |
38
|
|
|
{ |
39
|
|
|
if (0 === strpos($method, 'create')) { |
40
|
|
|
return $this->callCreateOnObject($method, $args); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if (0 === strpos($method, 'update')) { |
44
|
|
|
return $this->callUpdateOnObject($method, $args); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (0 === strpos($method, 'delete')) { |
48
|
|
|
return $this->callDeleteOnObject($method, $args); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (0 === strpos($method, 'get')) { |
52
|
|
|
return $this->callGetOnObject($method, $args); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return (new BaseObject(''))->$method; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create object dynamically |
60
|
|
|
* |
61
|
|
|
* @param $method |
62
|
|
|
* @param $args |
63
|
|
|
* @return bool |
64
|
|
|
*/ |
65
|
|
View Code Duplication |
private function callCreateOnObject($method, $args) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$type = substr($method, 6); |
68
|
|
|
$class = '\\Surge\\LaravelSalesforce\\Objects\\' . $type; |
69
|
|
|
|
70
|
|
|
if (class_exists($class)) { |
71
|
|
|
return (new $class())->create($args[0]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return (new BaseObject($type))->create($args[0]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
private function callUpdateOnObject($method, $args) |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
$type = substr($method, 6); |
80
|
|
|
$class = '\\Surge\\LaravelSalesforce\\Objects\\' . $type; |
81
|
|
|
|
82
|
|
|
if (class_exists($class)) { |
83
|
|
|
return (new $class())->update($args[0]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return (new BaseObject($type))->update($type, $args[0]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
View Code Duplication |
private function callDeleteOnObject($method, $args) |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
$type = substr($method, 6); |
92
|
|
|
$class = '\\Surge\\LaravelSalesforce\\Objects\\' . $type; |
93
|
|
|
|
94
|
|
|
if (class_exists($class)) { |
95
|
|
|
return (new $class())->delete($args[0]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return (new BaseObject($type))->delete($type, $args[0]); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
View Code Duplication |
private function callGetOnObject($method, $args) |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
$type = substr($method, 3); |
104
|
|
|
$class = '\\Surge\\LaravelSalesforce\\Objects\\' . $type; |
105
|
|
|
|
106
|
|
|
if (class_exists($class)) { |
107
|
|
|
return (new $class())->get($args[0]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return (new BaseObject($type))->get($args[0]); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
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: