1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acquia\LiftClient\Entity; |
4
|
|
|
|
5
|
|
|
use Acquia\LiftClient\Exception\LiftSdkException; |
6
|
|
|
use DateTime; |
7
|
|
|
|
8
|
|
|
class Rule extends Entity |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param array $array |
12
|
|
|
*/ |
13
|
|
|
public function __construct(array $array = []) |
14
|
|
|
{ |
15
|
|
|
parent::__construct($array); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Sets the 'id' parameter. |
20
|
|
|
* |
21
|
|
|
* @param string $id |
22
|
|
|
* |
23
|
|
|
* @throws \Acquia\LiftClient\Exception\LiftSdkException |
24
|
|
|
* |
25
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
26
|
|
|
*/ |
27
|
|
|
public function setId($id) |
28
|
|
|
{ |
29
|
|
|
if (!is_string($id)) { |
30
|
|
|
throw new LiftSdkException('Argument must be an instance of string.'); |
31
|
|
|
} |
32
|
|
|
$this['id'] = $id; |
33
|
|
|
|
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Gets the 'id' parameter. |
39
|
|
|
* |
40
|
|
|
* @return string The Identifier of the Rule |
41
|
|
|
*/ |
42
|
|
|
public function getId() |
43
|
|
|
{ |
44
|
|
|
return $this->getEntityValue('id', ''); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Sets the 'label' parameter. |
49
|
|
|
* |
50
|
|
|
* @param string $label |
51
|
|
|
* |
52
|
|
|
* @throws \Acquia\LiftClient\Exception\LiftSdkException |
53
|
|
|
* |
54
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
55
|
|
|
*/ |
56
|
|
|
public function setLabel($label) |
57
|
|
|
{ |
58
|
|
|
if (!is_string($label)) { |
59
|
|
|
throw new LiftSdkException('Argument must be an instance of string.'); |
60
|
|
|
} |
61
|
|
|
$this['label'] = $label; |
62
|
|
|
|
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Gets the 'label' parameter. |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getLabel() |
72
|
|
|
{ |
73
|
|
|
return $this->getEntityValue('label', ''); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Sets the 'description' parameter. |
78
|
|
|
* |
79
|
|
|
* @param string $description |
80
|
|
|
* |
81
|
|
|
* @throws \Acquia\LiftClient\Exception\LiftSdkException |
82
|
|
|
* |
83
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
84
|
|
|
*/ |
85
|
|
|
public function setDescription($description) |
86
|
|
|
{ |
87
|
|
|
if (!is_string($description)) { |
88
|
|
|
throw new LiftSdkException('Argument must be an instance of string.'); |
89
|
|
|
} |
90
|
|
|
$this['description'] = $description; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Gets the 'description' parameter. |
97
|
|
|
* |
98
|
|
|
* @return string The Description of the Rule |
99
|
|
|
*/ |
100
|
|
|
public function getDescription() |
101
|
|
|
{ |
102
|
|
|
return $this->getEntityValue('description', ''); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Sets the 'slot_id' parameter. |
107
|
|
|
* |
108
|
|
|
* @param string $slotId |
109
|
|
|
* |
110
|
|
|
* @throws \Acquia\LiftClient\Exception\LiftSdkException |
111
|
|
|
* |
112
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
113
|
|
|
*/ |
114
|
|
|
public function setSlotId($slotId) |
115
|
|
|
{ |
116
|
|
|
if (!is_string($slotId)) { |
117
|
|
|
throw new LiftSdkException('Argument must be an instance of string.'); |
118
|
|
|
} |
119
|
|
|
$this['slot_id'] = $slotId; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Gets the 'slot_id' parameter. |
126
|
|
|
* |
127
|
|
|
* @return string The Description of the Rule |
128
|
|
|
*/ |
129
|
|
|
public function getSlotId() |
130
|
|
|
{ |
131
|
|
|
return $this->getEntityValue('slot_id', ''); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Sets the 'weight' parameter. |
136
|
|
|
* |
137
|
|
|
* @param int $weight |
138
|
|
|
* |
139
|
|
|
* @throws \Acquia\LiftClient\Exception\LiftSdkException |
140
|
|
|
* |
141
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
142
|
|
|
*/ |
143
|
|
|
public function setWeight($weight) |
144
|
|
|
{ |
145
|
|
|
if (!is_integer($weight)) { |
146
|
|
|
throw new LiftSdkException('Argument must be an instance of integer.'); |
147
|
|
|
} |
148
|
|
|
$this['weight'] = $weight; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Gets the 'weight' parameter. |
155
|
|
|
* |
156
|
|
|
* @return int The weight of the Rule |
157
|
|
|
*/ |
158
|
|
|
public function getWeight() |
159
|
|
|
{ |
160
|
|
|
return $this->getEntityValue('weight', 0); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Sets the 'content' parameter. |
165
|
|
|
* |
166
|
|
|
* @param Content[] $contentList |
167
|
|
|
* |
168
|
|
|
* @throws \Acquia\LiftClient\Exception\LiftSdkException |
169
|
|
|
* |
170
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
171
|
|
|
*/ |
172
|
|
|
public function setContent(array $contentList) |
173
|
|
|
{ |
174
|
|
|
$this['content'] = []; |
175
|
|
|
foreach ($contentList as $content) { |
176
|
|
|
// We need to 'normalize' the data. |
177
|
|
|
$this['content'][] = $content->getArrayCopy(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Gets the 'content' parameter. |
185
|
|
|
* |
186
|
|
|
* @return Content[] The list of content this rule applies to |
187
|
|
|
*/ |
188
|
|
|
public function getContent() |
189
|
|
|
{ |
190
|
|
|
$contentList = $this->getEntityValue('content', ''); |
191
|
|
|
$ret = []; |
192
|
|
|
foreach ($contentList as $content) { |
193
|
|
|
$ret[] = new Content($content); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
return $ret; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Sets the 'segment' parameter. |
201
|
|
|
* |
202
|
|
|
* @param string $segment |
203
|
|
|
* |
204
|
|
|
* @throws \Acquia\LiftClient\Exception\LiftSdkException |
205
|
|
|
* |
206
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
207
|
|
|
*/ |
208
|
|
|
public function setSegment($segment) |
209
|
|
|
{ |
210
|
|
|
if (!is_string($segment)) { |
211
|
|
|
throw new LiftSdkException('Argument must be an instance of integer.'); |
212
|
|
|
} |
213
|
|
|
$this['segment'] = $segment; |
214
|
|
|
|
215
|
|
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Gets the 'segment' parameter. |
220
|
|
|
* |
221
|
|
|
* @return string |
222
|
|
|
*/ |
223
|
|
|
public function getSegment() |
224
|
|
|
{ |
225
|
|
|
return $this->getEntityValue('segment', ''); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Sets the 'status' parameter. |
230
|
|
|
* |
231
|
|
|
* @param string $status |
232
|
|
|
* |
233
|
|
|
* @throws \Acquia\LiftClient\Exception\LiftSdkException |
234
|
|
|
* |
235
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
236
|
|
|
*/ |
237
|
|
|
public function setStatus($status) |
238
|
|
|
{ |
239
|
|
|
if (!is_string($status)) { |
240
|
|
|
throw new LiftSdkException('Argument must be an instance of integer.'); |
241
|
|
|
} |
242
|
|
|
if ($status !== 'published' && $status !== 'unpublished' && $status !== 'archived') { |
243
|
|
|
throw new LiftSdkException('Status much be either published, unpublished or archived'); |
244
|
|
|
} |
245
|
|
|
$this['status'] = $status; |
246
|
|
|
|
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Gets the 'status' parameter. |
252
|
|
|
* |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
public function getStatus() |
256
|
|
|
{ |
257
|
|
|
return $this->getEntityValue('status', ''); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Gets the 'created' parameter. |
262
|
|
|
* |
263
|
|
|
* @return DateTime|false |
264
|
|
|
*/ |
265
|
|
|
public function getCreated() |
266
|
|
|
{ |
267
|
|
|
$date = $this->getEntityValue('created', 0); |
268
|
|
|
$datetime = DateTime::createFromFormat(DateTime::ISO8601, $date); |
269
|
|
|
|
270
|
|
|
return $datetime; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Gets the 'updated' parameter. |
275
|
|
|
* |
276
|
|
|
* @return DateTime|false |
277
|
|
|
*/ |
278
|
|
|
public function getUpdated() |
279
|
|
|
{ |
280
|
|
|
$date = $this->getEntityValue('updated', 0); |
281
|
|
|
$datetime = DateTime::createFromFormat(DateTime::ISO8601, $date); |
282
|
|
|
|
283
|
|
|
return $datetime; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Sets the Rule test_config property. |
288
|
|
|
* |
289
|
|
|
* @param \Acquia\LiftClient\Entity\TestConfigInterface $testConfig |
290
|
|
|
* |
291
|
|
|
* @return \Acquia\LiftClient\Entity\Rule |
292
|
|
|
*/ |
293
|
|
|
public function setTestConfig(TestConfigInterface $testConfig) |
294
|
|
|
{ |
295
|
|
|
// To facilitate TypeHinting in PHPStorm we redefine what $testConfig is |
296
|
|
|
// here. We know it inherits from the TestConfigInterface and is a child |
297
|
|
|
// of TestConfigBase. |
298
|
|
|
/** @var \Acquia\LiftClient\Entity\TestConfigBase $testConfig */ |
299
|
|
|
|
300
|
|
|
// Get class of the testConfig object. |
301
|
|
|
$type = get_class($testConfig); |
302
|
|
|
|
303
|
|
|
// Only allow one test type at a time. |
304
|
|
|
$this['testconfig'] = []; |
305
|
|
|
switch ($type) { |
306
|
|
|
case 'Acquia\LiftClient\Entity\TestConfigAb': |
307
|
|
|
$this['testconfig']['ab'] = $testConfig->getArrayCopy(); |
308
|
|
|
break; |
309
|
|
|
case 'Acquia\LiftClient\Entity\TestConfigMab': |
310
|
|
|
$this['testconfig']['mab'] = $testConfig->getArrayCopy(); |
311
|
|
|
break; |
312
|
|
|
case 'Acquia\LiftClient\Entity\TestConfigTarget': |
313
|
|
|
$this['testconfig']['target'] = $testConfig->getArrayCopy(); |
314
|
|
|
break; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
return $this; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Gets the 'test_config' parameter. |
322
|
|
|
* |
323
|
|
|
* @return \Acquia\LiftClient\Entity\TestConfigInterface|null $testConfig |
324
|
|
|
*/ |
325
|
|
|
public function getTestConfig() |
326
|
|
|
{ |
327
|
|
|
$testConfig = $this->getEntityValue('testconfig', []); |
328
|
|
|
// We know the array only has one possible set of options. |
329
|
|
|
// Get its key and value. |
330
|
|
|
reset($testConfig); |
331
|
|
|
$key = key($testConfig); |
332
|
|
|
|
333
|
|
|
// Based on the config, we load the different objects. |
334
|
|
|
switch ($key) { |
335
|
|
|
case 'ab': |
336
|
|
|
return new TestConfigAb($testConfig[$key]); |
337
|
|
|
case 'mab': |
338
|
|
|
return new TestConfigMab($testConfig[$key]); |
339
|
|
|
case 'target': |
340
|
|
|
return new TestConfigTarget($testConfig[$key]); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
return null; |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|