|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/hubspot/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/hubspot/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\hubspot\services\resources\traits; |
|
10
|
|
|
|
|
11
|
|
|
use flipbox\hubspot\builders\ObjectBuilderInterface; |
|
12
|
|
|
use flipbox\hubspot\connections\ConnectionInterface; |
|
13
|
|
|
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface; |
|
14
|
|
|
use League\Pipeline\PipelineBuilderInterface; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
use Psr\SimpleCache\CacheInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Flipbox Factory <[email protected]> |
|
20
|
|
|
* @since 1.0.0 |
|
21
|
|
|
*/ |
|
22
|
|
|
trait AddObjectTrait |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @param string $id |
|
26
|
|
|
* @param array $payload |
|
27
|
|
|
* @param ConnectionInterface|null $connection |
|
28
|
|
|
* @param CacheInterface|null $cache |
|
29
|
|
|
* @param TransformerCollectionInterface|null $transformer |
|
30
|
|
|
* @return PipelineBuilderInterface |
|
31
|
|
|
* @throws \yii\base\InvalidConfigException |
|
32
|
|
|
*/ |
|
33
|
|
|
public abstract function rawAddPipeline( |
|
34
|
|
|
string $id, |
|
35
|
|
|
array $payload, |
|
36
|
|
|
ConnectionInterface $connection = null, |
|
37
|
|
|
CacheInterface $cache = null, |
|
38
|
|
|
TransformerCollectionInterface $transformer = null |
|
39
|
|
|
): PipelineBuilderInterface; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $id |
|
43
|
|
|
* @param array $payload |
|
44
|
|
|
* @param ConnectionInterface|null $connection |
|
45
|
|
|
* @param CacheInterface|null $cache |
|
46
|
|
|
* @return callable |
|
47
|
|
|
* @throws \yii\base\InvalidConfigException |
|
48
|
|
|
*/ |
|
49
|
|
|
public abstract function rawHttpAddRelay( |
|
50
|
|
|
string $id, |
|
51
|
|
|
array $payload, |
|
52
|
|
|
ConnectionInterface $connection = null, |
|
53
|
|
|
CacheInterface $cache = null |
|
54
|
|
|
): callable; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param ObjectBuilderInterface $builder |
|
58
|
|
|
* @param ConnectionInterface|null $connection |
|
59
|
|
|
* @param CacheInterface|null $cache |
|
60
|
|
|
* @param TransformerCollectionInterface|null $transformer |
|
61
|
|
|
* @param null $source |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
* @throws \yii\base\InvalidConfigException |
|
64
|
|
|
*/ |
|
65
|
|
|
public function add( |
|
66
|
|
|
ObjectBuilderInterface $builder, |
|
67
|
|
|
ConnectionInterface $connection = null, |
|
68
|
|
|
CacheInterface $cache = null, |
|
69
|
|
|
TransformerCollectionInterface $transformer = null, |
|
70
|
|
|
$source = null |
|
71
|
|
|
) { |
|
72
|
|
|
return $this->rawAdd( |
|
73
|
|
|
$builder->getId(), |
|
74
|
|
|
$builder->getPayload(), |
|
75
|
|
|
$connection, |
|
76
|
|
|
$cache, |
|
77
|
|
|
$transformer, |
|
78
|
|
|
$source |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $id |
|
84
|
|
|
* @param array $payload |
|
85
|
|
|
* @param ConnectionInterface|null $connection |
|
86
|
|
|
* @param CacheInterface|null $cache |
|
87
|
|
|
* @param TransformerCollectionInterface|null $transformer |
|
88
|
|
|
* @param null $source |
|
89
|
|
|
* @return mixed |
|
90
|
|
|
* @throws \yii\base\InvalidConfigException |
|
91
|
|
|
*/ |
|
92
|
|
|
public function rawAdd( |
|
93
|
|
|
string $id, |
|
94
|
|
|
array $payload, |
|
95
|
|
|
ConnectionInterface $connection = null, |
|
96
|
|
|
CacheInterface $cache = null, |
|
97
|
|
|
TransformerCollectionInterface $transformer = null, |
|
98
|
|
|
$source = null |
|
99
|
|
|
) { |
|
100
|
|
|
return $this->rawAddPipeline( |
|
101
|
|
|
$id, |
|
102
|
|
|
$payload, |
|
103
|
|
|
$connection, |
|
104
|
|
|
$cache, |
|
105
|
|
|
$transformer |
|
106
|
|
|
)($source); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param ObjectBuilderInterface $builder |
|
111
|
|
|
* @param ConnectionInterface|null $connection |
|
112
|
|
|
* @param CacheInterface|null $cache |
|
113
|
|
|
* @param TransformerCollectionInterface|null $transformer |
|
114
|
|
|
* @return PipelineBuilderInterface |
|
115
|
|
|
* @throws \yii\base\InvalidConfigException |
|
116
|
|
|
*/ |
|
117
|
|
|
public function addPipeline( |
|
118
|
|
|
ObjectBuilderInterface $builder, |
|
119
|
|
|
ConnectionInterface $connection = null, |
|
120
|
|
|
CacheInterface $cache = null, |
|
121
|
|
|
TransformerCollectionInterface $transformer = null |
|
122
|
|
|
): PipelineBuilderInterface { |
|
123
|
|
|
return $this->rawAddPipeline( |
|
124
|
|
|
$builder->getId(), |
|
125
|
|
|
$builder->getPayload(), |
|
126
|
|
|
$connection, |
|
127
|
|
|
$cache, |
|
128
|
|
|
$transformer |
|
129
|
|
|
); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param ObjectBuilderInterface $builder |
|
134
|
|
|
* @param ConnectionInterface|null $connection |
|
135
|
|
|
* @param CacheInterface|null $cache |
|
136
|
|
|
* @return callable |
|
137
|
|
|
* @throws \yii\base\InvalidConfigException |
|
138
|
|
|
*/ |
|
139
|
|
|
public function httpAddRelay( |
|
140
|
|
|
ObjectBuilderInterface $builder, |
|
141
|
|
|
ConnectionInterface $connection = null, |
|
142
|
|
|
CacheInterface $cache = null |
|
143
|
|
|
): callable { |
|
144
|
|
|
return $this->rawHttpAddRelay( |
|
145
|
|
|
$builder->getId(), |
|
146
|
|
|
$builder->getPayload(), |
|
147
|
|
|
$connection, |
|
148
|
|
|
$cache |
|
149
|
|
|
); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @param ObjectBuilderInterface $builder |
|
154
|
|
|
* @param ConnectionInterface|null $connection |
|
155
|
|
|
* @param CacheInterface|null $cache |
|
156
|
|
|
* @return ResponseInterface |
|
157
|
|
|
* @throws \yii\base\InvalidConfigException |
|
158
|
|
|
*/ |
|
159
|
|
|
public function httpAdd( |
|
160
|
|
|
ObjectBuilderInterface $builder, |
|
161
|
|
|
ConnectionInterface $connection = null, |
|
162
|
|
|
CacheInterface $cache = null |
|
163
|
|
|
): ResponseInterface { |
|
164
|
|
|
return $this->rawHttpAdd( |
|
165
|
|
|
$builder->getId(), |
|
166
|
|
|
$builder->getPayload(), |
|
167
|
|
|
$connection, |
|
|
|
|
|
|
168
|
|
|
$cache |
|
|
|
|
|
|
169
|
|
|
); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @param string $id |
|
174
|
|
|
* @param array $payload |
|
175
|
|
|
* @param ConnectionInterface|null $connection |
|
176
|
|
|
* @param CacheInterface|null $cache |
|
177
|
|
|
* @return ResponseInterface |
|
178
|
|
|
* @throws \yii\base\InvalidConfigException |
|
179
|
|
|
*/ |
|
180
|
|
|
public function rawHttpAdd( |
|
181
|
|
|
string $id, |
|
182
|
|
|
array $payload, |
|
183
|
|
|
ConnectionInterface $connection, |
|
184
|
|
|
CacheInterface $cache |
|
185
|
|
|
): ResponseInterface { |
|
186
|
|
|
return $this->rawHttpAddRelay( |
|
187
|
|
|
$id, |
|
188
|
|
|
$payload, |
|
189
|
|
|
$connection, |
|
190
|
|
|
$cache |
|
191
|
|
|
)(); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):