1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipbox/relay-salesforce/blob/master/LICENSE.md |
6
|
|
|
* @link https://github.com/flipbox/relay-salesforce |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Flipbox\Relay\Salesforce\Builder\Resources; |
10
|
|
|
|
11
|
|
|
use Flipbox\Relay\Middleware\SimpleCache as CacheMiddleware; |
12
|
|
|
use Flipbox\Relay\Salesforce\AuthorizationInterface; |
13
|
|
|
use Flipbox\Relay\Salesforce\Builder\HttpRelayBuilder; |
14
|
|
|
use Flipbox\Relay\Salesforce\InstanceInterface; |
15
|
|
|
use Flipbox\Relay\Salesforce\Middleware\Resource\Resources as ResourcesMiddleware; |
16
|
|
|
use Psr\Log\LoggerInterface; |
17
|
|
|
use Psr\SimpleCache\CacheInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Flipbox Factory <[email protected]> |
21
|
|
|
* @since 1.0.1 |
22
|
|
|
*/ |
23
|
|
|
class Resources extends HttpRelayBuilder |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Upsert constructor. |
27
|
|
|
* @param InstanceInterface $instance |
28
|
|
|
* @param AuthorizationInterface $authorization |
29
|
|
|
* @param CacheInterface $cache |
30
|
|
|
* @param LoggerInterface|null $logger |
31
|
|
|
* @param array $config |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
InstanceInterface $instance, |
35
|
|
|
AuthorizationInterface $authorization, |
36
|
|
|
CacheInterface $cache, |
37
|
|
|
LoggerInterface $logger = null, |
38
|
|
|
$config = [] |
39
|
|
|
) { |
40
|
|
|
parent::__construct($instance, $authorization, $logger, $config); |
41
|
|
|
|
42
|
|
|
$this->addUri($logger) |
43
|
|
|
->addCache($cache, $logger); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param LoggerInterface|null $logger |
48
|
|
|
* @return $this |
49
|
|
|
*/ |
50
|
|
|
protected function addUri(LoggerInterface $logger = null) |
51
|
|
|
{ |
52
|
|
|
return $this->addAfter('uri', [ |
53
|
|
|
'class' => ResourcesMiddleware::class, |
54
|
|
|
'logger' => $logger ?: $this->getLogger() |
55
|
|
|
], 'instance'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param CacheInterface $cache |
60
|
|
|
* @param LoggerInterface|null $logger |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
|
|
protected function addCache(CacheInterface $cache, LoggerInterface $logger = null) |
64
|
|
|
{ |
65
|
|
|
return $this->addBefore('cache', [ |
66
|
|
|
'class' => CacheMiddleware::class, |
67
|
|
|
'logger' => $logger ?: $this->getLogger(), |
68
|
|
|
'cache' => $cache |
69
|
|
|
], 'token'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|