1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Commercetools\Core\Builder\Update; |
4
|
|
|
|
5
|
|
|
use Commercetools\Core\Error\InvalidArgumentException; |
6
|
|
|
use Commercetools\Core\Request\AbstractAction; |
7
|
|
|
use Commercetools\Core\Request\Categories\Command\CategoryAddAssetAction; |
8
|
|
|
use Commercetools\Core\Request\Categories\Command\CategoryChangeAssetNameAction; |
9
|
|
|
use Commercetools\Core\Request\Categories\Command\CategoryChangeAssetOrderAction; |
10
|
|
|
use Commercetools\Core\Request\Categories\Command\CategoryChangeNameAction; |
11
|
|
|
use Commercetools\Core\Request\Categories\Command\CategoryChangeOrderHintAction; |
12
|
|
|
use Commercetools\Core\Request\Categories\Command\CategoryChangeParentAction; |
13
|
|
|
use Commercetools\Core\Request\Categories\Command\CategoryChangeSlugAction; |
14
|
|
|
use Commercetools\Core\Request\Categories\Command\CategoryRemoveAssetAction; |
15
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetAssetCustomFieldAction; |
16
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetAssetCustomTypeAction; |
17
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetAssetDescriptionAction; |
18
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetAssetKeyAction; |
19
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetAssetSourcesAction; |
20
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetAssetTagsAction; |
21
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetCustomFieldAction; |
22
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetCustomTypeAction; |
23
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetDescriptionAction; |
24
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetExternalIdAction; |
25
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetKeyAction; |
26
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetMetaDescriptionAction; |
27
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetMetaKeywordsAction; |
28
|
|
|
use Commercetools\Core\Request\Categories\Command\CategorySetMetaTitleAction; |
29
|
|
|
|
30
|
|
|
class CategoriesActionBuilder |
31
|
|
|
{ |
32
|
|
|
private $actions = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#add-asset |
36
|
|
|
* @param CategoryAddAssetAction|callable $action |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
1 |
|
public function addAsset($action = null) |
40
|
|
|
{ |
41
|
1 |
|
$this->addAction($this->resolveAction(CategoryAddAssetAction::class, $action)); |
42
|
1 |
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#change-asset-name |
47
|
|
|
* @param CategoryChangeAssetNameAction|callable $action |
48
|
|
|
* @return $this |
49
|
|
|
*/ |
50
|
1 |
|
public function changeAssetName($action = null) |
51
|
|
|
{ |
52
|
1 |
|
$this->addAction($this->resolveAction(CategoryChangeAssetNameAction::class, $action)); |
53
|
1 |
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#change-asset-order |
58
|
|
|
* @param CategoryChangeAssetOrderAction|callable $action |
59
|
|
|
* @return $this |
60
|
|
|
*/ |
61
|
1 |
|
public function changeAssetOrder($action = null) |
62
|
|
|
{ |
63
|
1 |
|
$this->addAction($this->resolveAction(CategoryChangeAssetOrderAction::class, $action)); |
64
|
1 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#change-name |
69
|
|
|
* @param CategoryChangeNameAction|callable $action |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
1 |
|
public function changeName($action = null) |
73
|
|
|
{ |
74
|
1 |
|
$this->addAction($this->resolveAction(CategoryChangeNameAction::class, $action)); |
75
|
1 |
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#change-orderhint |
80
|
|
|
* @param CategoryChangeOrderHintAction|callable $action |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
1 |
|
public function changeOrderHint($action = null) |
84
|
|
|
{ |
85
|
1 |
|
$this->addAction($this->resolveAction(CategoryChangeOrderHintAction::class, $action)); |
86
|
1 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#change-parent |
91
|
|
|
* @param CategoryChangeParentAction|callable $action |
92
|
|
|
* @return $this |
93
|
|
|
*/ |
94
|
1 |
|
public function changeParent($action = null) |
95
|
|
|
{ |
96
|
1 |
|
$this->addAction($this->resolveAction(CategoryChangeParentAction::class, $action)); |
97
|
1 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#change-slug |
102
|
|
|
* @param CategoryChangeSlugAction|callable $action |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
1 |
|
public function changeSlug($action = null) |
106
|
|
|
{ |
107
|
1 |
|
$this->addAction($this->resolveAction(CategoryChangeSlugAction::class, $action)); |
108
|
1 |
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#remove-asset |
113
|
|
|
* @param CategoryRemoveAssetAction|callable $action |
114
|
|
|
* @return $this |
115
|
|
|
*/ |
116
|
1 |
|
public function removeAsset($action = null) |
117
|
|
|
{ |
118
|
1 |
|
$this->addAction($this->resolveAction(CategoryRemoveAssetAction::class, $action)); |
119
|
1 |
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#set-asset-customfield |
124
|
|
|
* @param CategorySetAssetCustomFieldAction|callable $action |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
1 |
|
public function setAssetCustomField($action = null) |
128
|
|
|
{ |
129
|
1 |
|
$this->addAction($this->resolveAction(CategorySetAssetCustomFieldAction::class, $action)); |
130
|
1 |
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#set-asset-custom-type |
135
|
|
|
* @param CategorySetAssetCustomTypeAction|callable $action |
136
|
|
|
* @return $this |
137
|
|
|
*/ |
138
|
1 |
|
public function setAssetCustomType($action = null) |
139
|
|
|
{ |
140
|
1 |
|
$this->addAction($this->resolveAction(CategorySetAssetCustomTypeAction::class, $action)); |
141
|
1 |
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#set-asset-description |
146
|
|
|
* @param CategorySetAssetDescriptionAction|callable $action |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
1 |
|
public function setAssetDescription($action = null) |
150
|
|
|
{ |
151
|
1 |
|
$this->addAction($this->resolveAction(CategorySetAssetDescriptionAction::class, $action)); |
152
|
1 |
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#set-asset-key |
157
|
|
|
* @param CategorySetAssetKeyAction|callable $action |
158
|
|
|
* @return $this |
159
|
|
|
*/ |
160
|
1 |
|
public function setAssetKey($action = null) |
161
|
|
|
{ |
162
|
1 |
|
$this->addAction($this->resolveAction(CategorySetAssetKeyAction::class, $action)); |
163
|
1 |
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#set-asset-tags |
168
|
|
|
* @param CategorySetAssetSourcesAction|callable $action |
169
|
|
|
* @return $this |
170
|
|
|
*/ |
171
|
1 |
|
public function setAssetSources($action = null) |
172
|
|
|
{ |
173
|
1 |
|
$this->addAction($this->resolveAction(CategorySetAssetSourcesAction::class, $action)); |
174
|
1 |
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @link https://docs.commercetools.com/http-api-projects-products.html#set-asset-tags |
179
|
|
|
* @param CategorySetAssetTagsAction|callable $action |
180
|
|
|
* @return $this |
181
|
|
|
*/ |
182
|
1 |
|
public function setAssetTags($action = null) |
183
|
|
|
{ |
184
|
1 |
|
$this->addAction($this->resolveAction(CategorySetAssetTagsAction::class, $action)); |
185
|
1 |
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* |
190
|
|
|
* @param CategorySetCustomFieldAction|callable $action |
191
|
|
|
* @return $this |
192
|
|
|
*/ |
193
|
1 |
|
public function setCustomField($action = null) |
194
|
|
|
{ |
195
|
1 |
|
$this->addAction($this->resolveAction(CategorySetCustomFieldAction::class, $action)); |
196
|
1 |
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* |
201
|
|
|
* @param CategorySetCustomTypeAction|callable $action |
202
|
|
|
* @return $this |
203
|
|
|
*/ |
204
|
1 |
|
public function setCustomType($action = null) |
205
|
|
|
{ |
206
|
1 |
|
$this->addAction($this->resolveAction(CategorySetCustomTypeAction::class, $action)); |
207
|
1 |
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#set-description |
212
|
|
|
* @param CategorySetDescriptionAction|callable $action |
213
|
|
|
* @return $this |
214
|
|
|
*/ |
215
|
1 |
|
public function setDescription($action = null) |
216
|
|
|
{ |
217
|
1 |
|
$this->addAction($this->resolveAction(CategorySetDescriptionAction::class, $action)); |
218
|
1 |
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#set-external-id |
223
|
|
|
* @param CategorySetExternalIdAction|callable $action |
224
|
|
|
* @return $this |
225
|
|
|
*/ |
226
|
1 |
|
public function setExternalId($action = null) |
227
|
|
|
{ |
228
|
1 |
|
$this->addAction($this->resolveAction(CategorySetExternalIdAction::class, $action)); |
229
|
1 |
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#set-key |
234
|
|
|
* @param CategorySetKeyAction|callable $action |
235
|
|
|
* @return $this |
236
|
|
|
*/ |
237
|
1 |
|
public function setKey($action = null) |
238
|
|
|
{ |
239
|
1 |
|
$this->addAction($this->resolveAction(CategorySetKeyAction::class, $action)); |
240
|
1 |
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#set-meta-description |
245
|
|
|
* @param CategorySetMetaDescriptionAction|callable $action |
246
|
|
|
* @return $this |
247
|
|
|
*/ |
248
|
1 |
|
public function setMetaDescription($action = null) |
249
|
|
|
{ |
250
|
1 |
|
$this->addAction($this->resolveAction(CategorySetMetaDescriptionAction::class, $action)); |
251
|
1 |
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#set-meta-keywords |
256
|
|
|
* @param CategorySetMetaKeywordsAction|callable $action |
257
|
|
|
* @return $this |
258
|
|
|
*/ |
259
|
1 |
|
public function setMetaKeywords($action = null) |
260
|
|
|
{ |
261
|
1 |
|
$this->addAction($this->resolveAction(CategorySetMetaKeywordsAction::class, $action)); |
262
|
1 |
|
return $this; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @link https://docs.commercetools.com/http-api-projects-categories.html#set-meta-title |
267
|
|
|
* @param CategorySetMetaTitleAction|callable $action |
268
|
|
|
* @return $this |
269
|
|
|
*/ |
270
|
1 |
|
public function setMetaTitle($action = null) |
271
|
|
|
{ |
272
|
1 |
|
$this->addAction($this->resolveAction(CategorySetMetaTitleAction::class, $action)); |
273
|
1 |
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @return CategoriesActionBuilder |
278
|
|
|
*/ |
279
|
|
|
public function of() |
280
|
|
|
{ |
281
|
|
|
return new self(); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param $class |
286
|
|
|
* @param $action |
287
|
|
|
* @return AbstractAction |
288
|
|
|
* @throws InvalidArgumentException |
289
|
|
|
*/ |
290
|
22 |
|
private function resolveAction($class, $action = null) |
291
|
|
|
{ |
292
|
22 |
|
if (is_null($action) || is_callable($action)) { |
293
|
22 |
|
$callback = $action; |
294
|
22 |
|
$emptyAction = $class::of(); |
295
|
22 |
|
$action = $this->callback($emptyAction, $callback); |
296
|
|
|
} |
297
|
22 |
|
if ($action instanceof $class) { |
298
|
22 |
|
return $action; |
299
|
|
|
} |
300
|
|
|
throw new InvalidArgumentException( |
301
|
|
|
sprintf('Expected method to be called with or callable to return %s', $class) |
302
|
|
|
); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @param $action |
307
|
|
|
* @param callable $callback |
308
|
|
|
* @return AbstractAction |
309
|
|
|
*/ |
310
|
22 |
|
private function callback($action, callable $callback = null) |
311
|
|
|
{ |
312
|
22 |
|
if (!is_null($callback)) { |
313
|
|
|
$action = $callback($action); |
314
|
|
|
} |
315
|
22 |
|
return $action; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param AbstractAction $action |
320
|
|
|
* @return $this; |
321
|
|
|
*/ |
322
|
22 |
|
public function addAction(AbstractAction $action) |
323
|
|
|
{ |
324
|
22 |
|
$this->actions[] = $action; |
325
|
22 |
|
return $this; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @return array |
330
|
|
|
*/ |
331
|
22 |
|
public function getActions() |
332
|
|
|
{ |
333
|
22 |
|
return $this->actions; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @param array $actions |
338
|
|
|
* @return $this |
339
|
|
|
*/ |
340
|
|
|
public function setActions(array $actions) |
341
|
|
|
{ |
342
|
|
|
$this->actions = $actions; |
343
|
|
|
return $this; |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|