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\Project\Command\ProjectChangeCountriesAction; |
8
|
|
|
use Commercetools\Core\Request\Project\Command\ProjectChangeCountryTaxRateFallbackEnabledAction; |
9
|
|
|
use Commercetools\Core\Request\Project\Command\ProjectChangeCurrenciesAction; |
10
|
|
|
use Commercetools\Core\Request\Project\Command\ProjectChangeLanguagesAction; |
11
|
|
|
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesConfigurationAction; |
12
|
|
|
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesEnabledAction; |
13
|
|
|
use Commercetools\Core\Request\Project\Command\ProjectChangeNameAction; |
14
|
|
|
use Commercetools\Core\Request\Project\Command\ProjectSetExternalOAuthAction; |
15
|
|
|
use Commercetools\Core\Request\Project\Command\ProjectSetShippingRateInputTypeAction; |
16
|
|
|
|
17
|
|
|
class ProjectActionBuilder |
18
|
|
|
{ |
19
|
|
|
private $actions = []; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @link https://docs.commercetools.com/http-api-projects-project.html#change-countries |
23
|
|
|
* @param ProjectChangeCountriesAction|callable $action |
24
|
|
|
* @return $this |
25
|
|
|
*/ |
26
|
1 |
|
public function changeCountries($action = null) |
27
|
|
|
{ |
28
|
1 |
|
$this->addAction($this->resolveAction(ProjectChangeCountriesAction::class, $action)); |
29
|
1 |
|
return $this; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
* @param ProjectChangeCountryTaxRateFallbackEnabledAction|callable $action |
35
|
|
|
* @return $this |
36
|
|
|
*/ |
37
|
1 |
|
public function changeCountryTaxRateFallbackEnabled($action = null) |
38
|
|
|
{ |
39
|
1 |
|
$this->addAction($this->resolveAction(ProjectChangeCountryTaxRateFallbackEnabledAction::class, $action)); |
40
|
1 |
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @link https://docs.commercetools.com/http-api-projects-project.html#change-currencies |
45
|
|
|
* @param ProjectChangeCurrenciesAction|callable $action |
46
|
|
|
* @return $this |
47
|
|
|
*/ |
48
|
1 |
|
public function changeCurrencies($action = null) |
49
|
|
|
{ |
50
|
1 |
|
$this->addAction($this->resolveAction(ProjectChangeCurrenciesAction::class, $action)); |
51
|
1 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @link https://docs.commercetools.com/http-api-projects-project.html#change-languages |
56
|
|
|
* @param ProjectChangeLanguagesAction|callable $action |
57
|
|
|
* @return $this |
58
|
|
|
*/ |
59
|
1 |
|
public function changeLanguages($action = null) |
60
|
|
|
{ |
61
|
1 |
|
$this->addAction($this->resolveAction(ProjectChangeLanguagesAction::class, $action)); |
62
|
1 |
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @link https://docs.commercetools.com/http-api-projects-project.html#change-messages-enabled |
67
|
|
|
* @param ProjectChangeMessagesConfigurationAction|callable $action |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
1 |
|
public function changeMessagesConfiguration($action = null) |
71
|
|
|
{ |
72
|
1 |
|
$this->addAction($this->resolveAction(ProjectChangeMessagesConfigurationAction::class, $action)); |
73
|
1 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @link https://docs.commercetools.com/http-api-projects-project.html#change-messages-enabled |
78
|
|
|
* @param ProjectChangeMessagesEnabledAction|callable $action |
79
|
|
|
* @return $this |
80
|
|
|
*/ |
81
|
1 |
|
public function changeMessagesEnabled($action = null) |
82
|
|
|
{ |
83
|
1 |
|
$this->addAction($this->resolveAction(ProjectChangeMessagesEnabledAction::class, $action)); |
84
|
1 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @link https://docs.commercetools.com/http-api-projects-project.html#change-name |
89
|
|
|
* @param ProjectChangeNameAction|callable $action |
90
|
|
|
* @return $this |
91
|
|
|
*/ |
92
|
1 |
|
public function changeName($action = null) |
93
|
|
|
{ |
94
|
1 |
|
$this->addAction($this->resolveAction(ProjectChangeNameAction::class, $action)); |
95
|
1 |
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @link https://docs.commercetools.com/http-api-projects-project.html#set-externaloauth |
100
|
|
|
* @param ProjectSetExternalOAuthAction|callable $action |
101
|
|
|
* @return $this |
102
|
|
|
*/ |
103
|
2 |
|
public function setExternalOAuth($action = null) |
104
|
|
|
{ |
105
|
2 |
|
$this->addAction($this->resolveAction(ProjectSetExternalOAuthAction::class, $action)); |
106
|
2 |
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @link https://docs.commercetools.com/http-api-projects-project.html#set-shippingrateinputtype |
111
|
|
|
* @param ProjectSetShippingRateInputTypeAction|callable $action |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
1 |
|
public function setShippingRateInputType($action = null) |
115
|
|
|
{ |
116
|
1 |
|
$this->addAction($this->resolveAction(ProjectSetShippingRateInputTypeAction::class, $action)); |
117
|
1 |
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return ProjectActionBuilder |
122
|
|
|
*/ |
123
|
|
|
public static function of() |
124
|
|
|
{ |
125
|
|
|
return new self(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param $class |
130
|
|
|
* @param $action |
131
|
|
|
* @return AbstractAction |
132
|
|
|
* @throws InvalidArgumentException |
133
|
|
|
*/ |
134
|
10 |
|
private function resolveAction($class, $action = null) |
135
|
|
|
{ |
136
|
10 |
|
if (is_null($action) || is_callable($action)) { |
137
|
10 |
|
$callback = $action; |
138
|
10 |
|
$emptyAction = $class::of(); |
139
|
10 |
|
$action = $this->callback($emptyAction, $callback); |
140
|
|
|
} |
141
|
10 |
|
if ($action instanceof $class) { |
142
|
10 |
|
return $action; |
143
|
|
|
} |
144
|
|
|
throw new InvalidArgumentException( |
145
|
|
|
sprintf('Expected method to be called with or callable to return %s', $class) |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param $action |
151
|
|
|
* @param callable $callback |
152
|
|
|
* @return AbstractAction |
153
|
|
|
*/ |
154
|
10 |
|
private function callback($action, callable $callback = null) |
155
|
|
|
{ |
156
|
10 |
|
if (!is_null($callback)) { |
157
|
1 |
|
$action = $callback($action); |
158
|
|
|
} |
159
|
10 |
|
return $action; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param AbstractAction $action |
164
|
|
|
* @return $this; |
165
|
|
|
*/ |
166
|
10 |
|
public function addAction(AbstractAction $action) |
167
|
|
|
{ |
168
|
10 |
|
$this->actions[] = $action; |
169
|
10 |
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return array |
174
|
|
|
*/ |
175
|
10 |
|
public function getActions() |
176
|
|
|
{ |
177
|
10 |
|
return $this->actions; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param array $actions |
183
|
|
|
* @return $this |
184
|
|
|
*/ |
185
|
|
|
public function setActions(array $actions) |
186
|
|
|
{ |
187
|
|
|
$this->actions = $actions; |
188
|
|
|
return $this; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|