1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipbox/relay-hubspot/blob/master/LICENSE |
6
|
|
|
* @link https://github.com/flipbox/relay-hubspot |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Flipbox\Relay\HubSpot\Builder\Resources\ContactList; |
10
|
|
|
|
11
|
|
|
use Flipbox\Relay\HubSpot\AuthorizationInterface; |
12
|
|
|
use Flipbox\Relay\HubSpot\Builder\HttpRelayBuilder; |
13
|
|
|
use Flipbox\Relay\HubSpot\Middleware\JsonRequest as JsonMiddleware; |
14
|
|
|
use Flipbox\Relay\HubSpot\Middleware\Resources\ResourceV1; |
15
|
|
|
use Psr\Log\LoggerInterface; |
16
|
|
|
use Psr\SimpleCache\CacheInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Flipbox Factory <[email protected]> |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
*/ |
22
|
|
|
class GetContacts extends HttpRelayBuilder |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The node |
26
|
|
|
*/ |
27
|
|
|
const NODE = 'contacts'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The resource |
31
|
|
|
*/ |
32
|
|
|
const RESOURCE = 'lists'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $id |
36
|
|
|
* @param CacheInterface $cache |
37
|
|
|
* @param AuthorizationInterface $authorization |
38
|
|
|
* @param LoggerInterface|null $logger |
39
|
|
|
* @param array $config |
40
|
|
|
*/ |
41
|
|
|
public function __construct( |
42
|
|
|
string $id, |
43
|
|
|
AuthorizationInterface $authorization, |
44
|
|
|
CacheInterface $cache, |
45
|
|
|
LoggerInterface $logger = null, |
46
|
|
|
$config = [] |
47
|
|
|
) { |
48
|
|
|
parent::__construct($authorization, $logger, $config); |
49
|
|
|
|
50
|
|
|
$this->addUri($id, $logger) |
51
|
|
|
->addPayload($payload, $logger); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param array $payload |
56
|
|
|
* @param LoggerInterface|null $logger |
57
|
|
|
* @return $this |
58
|
|
|
*/ |
59
|
|
|
protected function addPayload(array $payload, LoggerInterface $logger = null) |
60
|
|
|
{ |
61
|
|
|
return $this->addAfter('body', [ |
62
|
|
|
'class' => JsonMiddleware::class, |
63
|
|
|
'payload' => $payload, |
64
|
|
|
'logger' => $logger ?: $this->getLogger() |
65
|
|
|
], 'uri'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $id |
70
|
|
|
* @param LoggerInterface|null $logger |
71
|
|
|
* @return $this |
72
|
|
|
*/ |
73
|
|
|
protected function addUri(string $id, LoggerInterface $logger = null) |
74
|
|
|
{ |
75
|
|
|
return $this->addBefore('uri', [ |
76
|
|
|
'class' => ResourceV1::class, |
77
|
|
|
'node' => self::NODE, |
78
|
|
|
'resource' => self::RESOURCE . '/' . $id . 'contacts/all', |
79
|
|
|
'logger' => $logger ?: $this->getLogger() |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.