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