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