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\ProductTypes\Command\ProductTypeAddAttributeDefinitionAction; |
8
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeAddLocalizedEnumValueAction; |
9
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeAddPlainEnumValueAction; |
10
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeAttributeConstraintAction; |
11
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeAttributeNameAction; |
12
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeAttributeOrderAction; |
13
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeAttributeOrderByNameAction; |
14
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeDescriptionAction; |
15
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeEnumKeyAction; |
16
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeInputHintAction; |
17
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeIsSearchableAction; |
18
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeLabelAction; |
19
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeLocalizedEnumLabelAction; |
20
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeLocalizedEnumValueOrderAction; |
21
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangeNameAction; |
22
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangePlainEnumLabelAction; |
23
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeChangePlainEnumValueOrderAction; |
24
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeRemoveAttributeDefinitionAction; |
25
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeRemoveEnumValuesAction; |
26
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeSetInputTipAction; |
27
|
|
|
use Commercetools\Core\Request\ProductTypes\Command\ProductTypeSetKeyAction; |
28
|
|
|
|
29
|
|
|
class ProductTypesActionBuilder |
30
|
|
|
{ |
31
|
|
|
private $actions = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#add-attributedefinition |
35
|
|
|
* @param ProductTypeAddAttributeDefinitionAction|callable $action |
36
|
|
|
* @return $this |
37
|
|
|
*/ |
38
|
1 |
|
public function addAttributeDefinition($action = null) |
39
|
|
|
{ |
40
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeAddAttributeDefinitionAction::class, $action)); |
41
|
1 |
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#add-localizableenumvalue-to-attributedefinition |
46
|
|
|
* @param ProductTypeAddLocalizedEnumValueAction|callable $action |
47
|
|
|
* @return $this |
48
|
|
|
*/ |
49
|
1 |
|
public function addLocalizedEnumValue($action = null) |
50
|
|
|
{ |
51
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeAddLocalizedEnumValueAction::class, $action)); |
52
|
1 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#add-plainenumvalue-to-attributedefinition |
57
|
|
|
* @param ProductTypeAddPlainEnumValueAction|callable $action |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
1 |
|
public function addPlainEnumValue($action = null) |
61
|
|
|
{ |
62
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeAddPlainEnumValueAction::class, $action)); |
63
|
1 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-attributedefinition-attributeconstraint |
68
|
|
|
* @param ProductTypeChangeAttributeConstraintAction|callable $action |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
1 |
|
public function changeAttributeConstraint($action = null) |
72
|
|
|
{ |
73
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeAttributeConstraintAction::class, $action)); |
74
|
1 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-attributedefinition-name |
79
|
|
|
* @param ProductTypeChangeAttributeNameAction|callable $action |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
1 |
|
public function changeAttributeName($action = null) |
83
|
|
|
{ |
84
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeAttributeNameAction::class, $action)); |
85
|
1 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes#change-the-order-of-attributedefinitions |
90
|
|
|
* @param ProductTypeChangeAttributeOrderAction|callable $action |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
1 |
|
public function changeAttributeOrder($action = null) |
94
|
|
|
{ |
95
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeAttributeOrderAction::class, $action)); |
96
|
1 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes#change-the-order-of-attributedefinitions |
101
|
|
|
* @param ProductTypeChangeAttributeOrderByNameAction|callable $action |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
1 |
|
public function changeAttributeOrderByName($action = null) |
105
|
|
|
{ |
106
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeAttributeOrderByNameAction::class, $action)); |
107
|
1 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-description |
112
|
|
|
* @param ProductTypeChangeDescriptionAction|callable $action |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
1 |
|
public function changeDescription($action = null) |
116
|
|
|
{ |
117
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeDescriptionAction::class, $action)); |
118
|
1 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-the-key-of-an-enumvalue |
123
|
|
|
* @param ProductTypeChangeEnumKeyAction|callable $action |
124
|
|
|
* @return $this |
125
|
|
|
*/ |
126
|
1 |
|
public function changeEnumKey($action = null) |
127
|
|
|
{ |
128
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeEnumKeyAction::class, $action)); |
129
|
1 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-attributedefinition-inputhint |
134
|
|
|
* @param ProductTypeChangeInputHintAction|callable $action |
135
|
|
|
* @return $this |
136
|
|
|
*/ |
137
|
1 |
|
public function changeInputHint($action = null) |
138
|
|
|
{ |
139
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeInputHintAction::class, $action)); |
140
|
1 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-attributedefinition-issearchable |
145
|
|
|
* @param ProductTypeChangeIsSearchableAction|callable $action |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
1 |
|
public function changeIsSearchable($action = null) |
149
|
|
|
{ |
150
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeIsSearchableAction::class, $action)); |
151
|
1 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-attributedefinition-label |
156
|
|
|
* @param ProductTypeChangeLabelAction|callable $action |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
1 |
|
public function changeLabel($action = null) |
160
|
|
|
{ |
161
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeLabelAction::class, $action)); |
162
|
1 |
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-the-label-of-an-localizedenumvalue |
167
|
|
|
* @param ProductTypeChangeLocalizedEnumLabelAction|callable $action |
168
|
|
|
* @return $this |
169
|
|
|
*/ |
170
|
1 |
|
public function changeLocalizedEnumValueLabel($action = null) |
171
|
|
|
{ |
172
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeLocalizedEnumLabelAction::class, $action)); |
173
|
1 |
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-the-order-of-localizedenumvalues |
178
|
|
|
* @param ProductTypeChangeLocalizedEnumValueOrderAction|callable $action |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
1 |
|
public function changeLocalizedEnumValueOrder($action = null) |
182
|
|
|
{ |
183
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeLocalizedEnumValueOrderAction::class, $action)); |
184
|
1 |
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-name |
189
|
|
|
* @param ProductTypeChangeNameAction|callable $action |
190
|
|
|
* @return $this |
191
|
|
|
*/ |
192
|
1 |
|
public function changeName($action = null) |
193
|
|
|
{ |
194
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangeNameAction::class, $action)); |
195
|
1 |
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-the-label-of-an-enumvalue |
200
|
|
|
* @param ProductTypeChangePlainEnumLabelAction|callable $action |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
1 |
|
public function changePlainEnumValueLabel($action = null) |
204
|
|
|
{ |
205
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangePlainEnumLabelAction::class, $action)); |
206
|
1 |
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#change-the-order-of-enumvalues |
211
|
|
|
* @param ProductTypeChangePlainEnumValueOrderAction|callable $action |
212
|
|
|
* @return $this |
213
|
|
|
*/ |
214
|
1 |
|
public function changePlainEnumValueOrder($action = null) |
215
|
|
|
{ |
216
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeChangePlainEnumValueOrderAction::class, $action)); |
217
|
1 |
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#remove-attributedefinition |
222
|
|
|
* @param ProductTypeRemoveAttributeDefinitionAction|callable $action |
223
|
|
|
* @return $this |
224
|
|
|
*/ |
225
|
1 |
|
public function removeAttributeDefinition($action = null) |
226
|
|
|
{ |
227
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeRemoveAttributeDefinitionAction::class, $action)); |
228
|
1 |
|
return $this; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#remove-enumvalues-from-attributedefinition |
233
|
|
|
* @param ProductTypeRemoveEnumValuesAction|callable $action |
234
|
|
|
* @return $this |
235
|
|
|
*/ |
236
|
1 |
|
public function removeEnumValues($action = null) |
237
|
|
|
{ |
238
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeRemoveEnumValuesAction::class, $action)); |
239
|
1 |
|
return $this; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#set-attributedefinition-inputtip |
244
|
|
|
* @param ProductTypeSetInputTipAction|callable $action |
245
|
|
|
* @return $this |
246
|
|
|
*/ |
247
|
1 |
|
public function setInputTip($action = null) |
248
|
|
|
{ |
249
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeSetInputTipAction::class, $action)); |
250
|
1 |
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @link https://docs.commercetools.com/http-api-projects-productTypes.html#set-key |
255
|
|
|
* @param ProductTypeSetKeyAction|callable $action |
256
|
|
|
* @return $this |
257
|
|
|
*/ |
258
|
1 |
|
public function setKey($action = null) |
259
|
|
|
{ |
260
|
1 |
|
$this->addAction($this->resolveAction(ProductTypeSetKeyAction::class, $action)); |
261
|
1 |
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @return ProductTypesActionBuilder |
266
|
|
|
*/ |
267
|
|
|
public static function of() |
268
|
|
|
{ |
269
|
|
|
return new self(); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @param $class |
274
|
|
|
* @param $action |
275
|
|
|
* @return AbstractAction |
276
|
|
|
* @throws InvalidArgumentException |
277
|
|
|
*/ |
278
|
21 |
|
private function resolveAction($class, $action = null) |
279
|
|
|
{ |
280
|
21 |
|
if (is_null($action) || is_callable($action)) { |
281
|
21 |
|
$callback = $action; |
282
|
21 |
|
$emptyAction = $class::of(); |
283
|
21 |
|
$action = $this->callback($emptyAction, $callback); |
284
|
|
|
} |
285
|
21 |
|
if ($action instanceof $class) { |
286
|
21 |
|
return $action; |
287
|
|
|
} |
288
|
|
|
throw new InvalidArgumentException( |
289
|
|
|
sprintf('Expected method to be called with or callable to return %s', $class) |
290
|
|
|
); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @param $action |
295
|
|
|
* @param callable $callback |
296
|
|
|
* @return AbstractAction |
297
|
|
|
*/ |
298
|
21 |
|
private function callback($action, callable $callback = null) |
299
|
|
|
{ |
300
|
21 |
|
if (!is_null($callback)) { |
301
|
|
|
$action = $callback($action); |
302
|
|
|
} |
303
|
21 |
|
return $action; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param AbstractAction $action |
308
|
|
|
* @return $this; |
309
|
|
|
*/ |
310
|
21 |
|
public function addAction(AbstractAction $action) |
311
|
|
|
{ |
312
|
21 |
|
$this->actions[] = $action; |
313
|
21 |
|
return $this; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @return array |
318
|
|
|
*/ |
319
|
21 |
|
public function getActions() |
320
|
|
|
{ |
321
|
21 |
|
return $this->actions; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @param array $actions |
327
|
|
|
* @return $this |
328
|
|
|
*/ |
329
|
|
|
public function setActions(array $actions) |
330
|
|
|
{ |
331
|
|
|
$this->actions = $actions; |
332
|
|
|
return $this; |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
|