1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipbox/salesforce/blob/master/LICENSE.md |
6
|
|
|
* @link https://github.com/flipbox/salesforce |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Flipbox\Salesforce\Resources; |
10
|
|
|
|
11
|
|
|
use Flipbox\Relay\Salesforce\Builder\Resources\SObject\Basic; |
12
|
|
|
use Flipbox\Relay\Salesforce\Builder\Resources\SObject\Describe; |
13
|
|
|
use Flipbox\Relay\Salesforce\Builder\Resources\SObject\Row\Create; |
14
|
|
|
use Flipbox\Relay\Salesforce\Builder\Resources\SObject\Row\Delete; |
15
|
|
|
use Flipbox\Relay\Salesforce\Builder\Resources\SObject\Row\Get; |
16
|
|
|
use Flipbox\Relay\Salesforce\Builder\Resources\SObject\Row\Update; |
17
|
|
|
use Flipbox\Relay\Salesforce\Builder\Resources\SObject\Row\Upsert; |
18
|
|
|
use Flipbox\Salesforce\Connections\ConnectionInterface; |
19
|
|
|
use Flipbox\Salesforce\Salesforce; |
20
|
|
|
use Psr\Http\Message\ResponseInterface; |
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
use Psr\SimpleCache\CacheInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Flipbox Factory <[email protected]> |
26
|
|
|
* @since 3.0.0 |
27
|
|
|
*/ |
28
|
|
|
class SObject |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The resource name |
33
|
|
|
*/ |
34
|
|
|
const SALESFORCE_RESOURCE = 'object'; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/******************************************* |
38
|
|
|
* BASIC |
39
|
|
|
*******************************************/ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param ConnectionInterface $connection |
43
|
|
|
* @param CacheInterface $cache |
44
|
|
|
* @param string $object |
45
|
|
|
* @param LoggerInterface|null $logger |
46
|
|
|
* @param array $config |
47
|
|
|
* @return ResponseInterface |
48
|
|
|
*/ |
49
|
|
|
public static function basic( |
50
|
|
|
string $object, |
51
|
|
|
ConnectionInterface $connection = null, |
52
|
|
|
CacheInterface $cache = null, |
53
|
|
|
LoggerInterface $logger = null, |
54
|
|
|
array $config = [] |
55
|
|
|
): ResponseInterface { |
56
|
|
|
return static::basicRelay( |
57
|
|
|
$object, |
58
|
|
|
$connection, |
59
|
|
|
$cache, |
60
|
|
|
$logger, |
61
|
|
|
$config |
62
|
|
|
)(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param ConnectionInterface $connection |
67
|
|
|
* @param CacheInterface $cache |
68
|
|
|
* @param string $object |
69
|
|
|
* @param LoggerInterface|null $logger |
70
|
|
|
* @param array $config |
71
|
|
|
* @return callable |
72
|
|
|
*/ |
73
|
|
|
public static function basicRelay( |
74
|
|
|
string $object, |
75
|
|
|
ConnectionInterface $connection = null, |
76
|
|
|
CacheInterface $cache = null, |
77
|
|
|
LoggerInterface $logger = null, |
78
|
|
|
array $config = [] |
79
|
|
|
): callable { |
80
|
|
|
$connection = $connection ?: Salesforce::getConnection(); |
81
|
|
|
|
82
|
|
|
$builder = new Basic( |
83
|
|
|
$connection, |
84
|
|
|
$connection, |
85
|
|
|
$cache ?: Salesforce::getCache(), |
86
|
|
|
$object, |
87
|
|
|
$logger ?: Salesforce::getLogger(), |
88
|
|
|
$config |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
return $builder->build(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/******************************************* |
95
|
|
|
* DESCRIBE |
96
|
|
|
*******************************************/ |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $object |
100
|
|
|
* @param ConnectionInterface $connection |
101
|
|
|
* @param CacheInterface $cache |
102
|
|
|
* @param LoggerInterface $logger |
103
|
|
|
* @param array $config |
104
|
|
|
* @return ResponseInterface |
105
|
|
|
*/ |
106
|
|
|
public static function describe( |
107
|
|
|
string $object, |
108
|
|
|
ConnectionInterface $connection = null, |
109
|
|
|
CacheInterface $cache = null, |
110
|
|
|
LoggerInterface $logger = null, |
111
|
|
|
array $config = [] |
112
|
|
|
): ResponseInterface { |
113
|
|
|
return static::describeRelay( |
114
|
|
|
$object, |
115
|
|
|
$connection, |
116
|
|
|
$cache, |
117
|
|
|
$logger, |
118
|
|
|
$config |
119
|
|
|
)(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $object |
124
|
|
|
* @param ConnectionInterface $connection |
125
|
|
|
* @param CacheInterface $cache |
126
|
|
|
* @param LoggerInterface $logger |
127
|
|
|
* @param array $config |
128
|
|
|
* @return callable |
129
|
|
|
*/ |
130
|
|
|
public static function describeRelay( |
131
|
|
|
string $object, |
132
|
|
|
ConnectionInterface $connection = null, |
133
|
|
|
CacheInterface $cache = null, |
134
|
|
|
LoggerInterface $logger = null, |
135
|
|
|
array $config = [] |
136
|
|
|
): callable { |
137
|
|
|
$connection = $connection ?: Salesforce::getConnection(); |
138
|
|
|
|
139
|
|
|
$builder = new Describe( |
140
|
|
|
$connection, |
141
|
|
|
$connection, |
142
|
|
|
$cache ?: Salesforce::getCache(), |
143
|
|
|
$object, |
144
|
|
|
$logger ?: Salesforce::getLogger(), |
145
|
|
|
$config |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
return $builder->build(); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/******************************************* |
153
|
|
|
* CREATE |
154
|
|
|
*******************************************/ |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param string $object |
158
|
|
|
* @param array $payload |
159
|
|
|
* @param ConnectionInterface $connection |
160
|
|
|
* @param LoggerInterface $logger |
161
|
|
|
* @param array $config |
162
|
|
|
* @return ResponseInterface |
163
|
|
|
*/ |
164
|
|
|
public static function create( |
165
|
|
|
string $object, |
166
|
|
|
array $payload, |
167
|
|
|
ConnectionInterface $connection = null, |
168
|
|
|
LoggerInterface $logger = null, |
169
|
|
|
array $config = [] |
170
|
|
|
): ResponseInterface { |
171
|
|
|
return static::createRelay( |
172
|
|
|
$object, |
173
|
|
|
$payload, |
174
|
|
|
$connection, |
175
|
|
|
$logger, |
176
|
|
|
$config |
177
|
|
|
)(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $object |
182
|
|
|
* @param array $payload |
183
|
|
|
* @param ConnectionInterface $connection |
184
|
|
|
* @param LoggerInterface $logger |
185
|
|
|
* @param array $config |
186
|
|
|
* @return callable |
187
|
|
|
*/ |
188
|
|
|
public static function createRelay( |
189
|
|
|
string $object, |
190
|
|
|
array $payload, |
191
|
|
|
ConnectionInterface $connection = null, |
192
|
|
|
LoggerInterface $logger = null, |
193
|
|
|
array $config = [] |
194
|
|
|
): callable { |
195
|
|
|
$connection = $connection ?: Salesforce::getConnection(); |
196
|
|
|
|
197
|
|
|
$builder = new Create( |
198
|
|
|
$connection, |
199
|
|
|
$connection, |
200
|
|
|
$object, |
201
|
|
|
$payload, |
202
|
|
|
$logger ?: Salesforce::getLogger(), |
203
|
|
|
$config |
204
|
|
|
); |
205
|
|
|
|
206
|
|
|
return $builder->build(); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
/******************************************* |
211
|
|
|
* READ |
212
|
|
|
*******************************************/ |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param ConnectionInterface $connection |
216
|
|
|
* @param CacheInterface $cache |
217
|
|
|
* @param string $object |
218
|
|
|
* @param string $id |
219
|
|
|
* @param LoggerInterface|null $logger |
220
|
|
|
* @param array $config |
221
|
|
|
* @return ResponseInterface |
222
|
|
|
*/ |
223
|
|
|
public static function read( |
224
|
|
|
string $object, |
225
|
|
|
string $id, |
226
|
|
|
ConnectionInterface $connection = null, |
227
|
|
|
CacheInterface $cache = null, |
228
|
|
|
LoggerInterface $logger = null, |
229
|
|
|
array $config = [] |
230
|
|
|
): ResponseInterface { |
231
|
|
|
return static::readRelay( |
232
|
|
|
$object, |
233
|
|
|
$id, |
234
|
|
|
$connection, |
235
|
|
|
$cache, |
236
|
|
|
$logger, |
237
|
|
|
$config |
238
|
|
|
)(); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @param ConnectionInterface $connection |
243
|
|
|
* @param CacheInterface $cache |
244
|
|
|
* @param string $object |
245
|
|
|
* @param string $id |
246
|
|
|
* @param LoggerInterface|null $logger |
247
|
|
|
* @param array $config |
248
|
|
|
* @return callable |
249
|
|
|
*/ |
250
|
|
|
public static function readRelay( |
251
|
|
|
string $object, |
252
|
|
|
string $id, |
253
|
|
|
ConnectionInterface $connection = null, |
254
|
|
|
CacheInterface $cache = null, |
255
|
|
|
LoggerInterface $logger = null, |
256
|
|
|
array $config = [] |
257
|
|
|
): callable { |
258
|
|
|
$connection = $connection ?: Salesforce::getConnection(); |
259
|
|
|
|
260
|
|
|
$builder = new Get( |
261
|
|
|
$connection, |
262
|
|
|
$connection, |
263
|
|
|
$cache ?: Salesforce::getCache(), |
264
|
|
|
$object, |
265
|
|
|
$id, |
266
|
|
|
$logger ?: Salesforce::getLogger(), |
267
|
|
|
$config |
268
|
|
|
); |
269
|
|
|
|
270
|
|
|
return $builder->build(); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/******************************************* |
274
|
|
|
* UPDATE |
275
|
|
|
*******************************************/ |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @param string $object |
279
|
|
|
* @param string $id |
280
|
|
|
* @param array $payload |
281
|
|
|
* @param ConnectionInterface $connection |
282
|
|
|
* @param CacheInterface $cache |
283
|
|
|
* @param LoggerInterface|null $logger |
284
|
|
|
* @param array $config |
285
|
|
|
* @return ResponseInterface |
286
|
|
|
*/ |
287
|
|
|
public static function update( |
288
|
|
|
string $object, |
289
|
|
|
array $payload, |
290
|
|
|
string $id, |
291
|
|
|
ConnectionInterface $connection = null, |
292
|
|
|
CacheInterface $cache = null, |
293
|
|
|
LoggerInterface $logger = null, |
294
|
|
|
array $config = [] |
295
|
|
|
): ResponseInterface { |
296
|
|
|
return static::updateRelay( |
297
|
|
|
$object, |
298
|
|
|
$payload, |
299
|
|
|
$id, |
300
|
|
|
$connection, |
301
|
|
|
$cache, |
302
|
|
|
$logger, |
303
|
|
|
$config |
304
|
|
|
)(); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @param string $object |
309
|
|
|
* @param string $id |
310
|
|
|
* @param array $payload |
311
|
|
|
* @param ConnectionInterface $connection |
312
|
|
|
* @param CacheInterface $cache |
313
|
|
|
* @param LoggerInterface|null $logger |
314
|
|
|
* @param array $config |
315
|
|
|
* @return callable |
316
|
|
|
*/ |
317
|
|
|
public static function updateRelay( |
318
|
|
|
string $object, |
319
|
|
|
array $payload, |
320
|
|
|
string $id, |
321
|
|
|
ConnectionInterface $connection = null, |
322
|
|
|
CacheInterface $cache = null, |
323
|
|
|
LoggerInterface $logger = null, |
324
|
|
|
array $config = [] |
325
|
|
|
): callable { |
326
|
|
|
$connection = $connection ?: Salesforce::getConnection(); |
327
|
|
|
|
328
|
|
|
$builder = new Update( |
329
|
|
|
$connection, |
330
|
|
|
$connection, |
331
|
|
|
$cache ?: Salesforce::getCache(), |
332
|
|
|
$object, |
333
|
|
|
$payload, |
334
|
|
|
$id, |
335
|
|
|
$logger ?: Salesforce::getLogger(), |
336
|
|
|
$config |
337
|
|
|
); |
338
|
|
|
|
339
|
|
|
return $builder->build(); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
|
343
|
|
|
/******************************************* |
344
|
|
|
* UPSERT |
345
|
|
|
*******************************************/ |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @param ConnectionInterface $connection |
349
|
|
|
* @param CacheInterface $cache |
350
|
|
|
* @param string $object |
351
|
|
|
* @param array $payload |
352
|
|
|
* @param string|null $id |
353
|
|
|
* @param LoggerInterface|null $logger |
354
|
|
|
* @param array $config |
355
|
|
|
* @return ResponseInterface |
356
|
|
|
*/ |
357
|
|
|
public static function upsert( |
358
|
|
|
string $object, |
359
|
|
|
array $payload, |
360
|
|
|
string $id = null, |
361
|
|
|
ConnectionInterface $connection = null, |
362
|
|
|
CacheInterface $cache = null, |
363
|
|
|
LoggerInterface $logger = null, |
364
|
|
|
array $config = [] |
365
|
|
|
): ResponseInterface { |
366
|
|
|
return static::upsertRelay( |
367
|
|
|
$object, |
368
|
|
|
$payload, |
369
|
|
|
$id, |
370
|
|
|
$connection, |
371
|
|
|
$cache, |
372
|
|
|
$logger, |
373
|
|
|
$config |
374
|
|
|
)(); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @param ConnectionInterface $connection |
379
|
|
|
* @param CacheInterface $cache |
380
|
|
|
* @param string $object |
381
|
|
|
* @param array $payload |
382
|
|
|
* @param string|null $id |
383
|
|
|
* @param LoggerInterface|null $logger |
384
|
|
|
* @param array $config |
385
|
|
|
* @return callable |
386
|
|
|
*/ |
387
|
|
|
public static function upsertRelay( |
388
|
|
|
string $object, |
389
|
|
|
array $payload, |
390
|
|
|
string $id = null, |
391
|
|
|
ConnectionInterface $connection = null, |
392
|
|
|
CacheInterface $cache = null, |
393
|
|
|
LoggerInterface $logger = null, |
394
|
|
|
array $config = [] |
395
|
|
|
): callable { |
396
|
|
|
$connection = $connection ?: Salesforce::getConnection(); |
397
|
|
|
|
398
|
|
|
$builder = new Upsert( |
399
|
|
|
$connection, |
400
|
|
|
$connection, |
401
|
|
|
$cache ?: Salesforce::getCache(), |
402
|
|
|
$object, |
403
|
|
|
$payload, |
404
|
|
|
empty($id) ? null : $id, |
405
|
|
|
$logger ?: Salesforce::getLogger(), |
406
|
|
|
$config |
407
|
|
|
); |
408
|
|
|
|
409
|
|
|
return $builder->build(); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
|
413
|
|
|
/******************************************* |
414
|
|
|
* DELETE |
415
|
|
|
*******************************************/ |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* @param string $object |
419
|
|
|
* @param string $id |
420
|
|
|
* @param ConnectionInterface $connection |
421
|
|
|
* @param CacheInterface $cache |
422
|
|
|
* @param LoggerInterface $logger |
423
|
|
|
* @param array $config |
424
|
|
|
* @return ResponseInterface |
425
|
|
|
*/ |
426
|
|
|
public static function delete( |
427
|
|
|
string $object, |
428
|
|
|
string $id, |
429
|
|
|
ConnectionInterface $connection = null, |
430
|
|
|
CacheInterface $cache = null, |
431
|
|
|
LoggerInterface $logger = null, |
432
|
|
|
array $config = [] |
433
|
|
|
): ResponseInterface { |
434
|
|
|
return static::deleteRelay( |
435
|
|
|
$object, |
436
|
|
|
$id, |
437
|
|
|
$connection, |
438
|
|
|
$cache, |
439
|
|
|
$logger, |
440
|
|
|
$config |
441
|
|
|
)(); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* @param string $object |
446
|
|
|
* @param string $id |
447
|
|
|
* @param ConnectionInterface $connection |
448
|
|
|
* @param CacheInterface $cache |
449
|
|
|
* @param LoggerInterface $logger |
450
|
|
|
* @param array $config |
451
|
|
|
* @return callable |
452
|
|
|
*/ |
453
|
|
|
public static function deleteRelay( |
454
|
|
|
string $object, |
455
|
|
|
string $id, |
456
|
|
|
ConnectionInterface $connection = null, |
457
|
|
|
CacheInterface $cache = null, |
458
|
|
|
LoggerInterface $logger = null, |
459
|
|
|
array $config = [] |
460
|
|
|
): callable { |
461
|
|
|
$connection = $connection ?: Salesforce::getConnection(); |
462
|
|
|
|
463
|
|
|
$builder = new Delete( |
464
|
|
|
$connection, |
465
|
|
|
$connection, |
466
|
|
|
$cache ?: Salesforce::getCache(), |
467
|
|
|
$object, |
468
|
|
|
$id, |
469
|
|
|
$logger ?: Salesforce::getLogger(), |
470
|
|
|
$config |
471
|
|
|
); |
472
|
|
|
|
473
|
|
|
return $builder->build(); |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
|