|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
|
4
|
|
|
* @date 10 October 2016 |
|
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* An Optimizely campaign change. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Change |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* The type of change to apply to the Page. Can be 'custom_code', 'custom_css', |
|
16
|
|
|
* 'attribute', 'mobile_live_variable', 'mobile_code_block', 'mobile_visual_change', |
|
17
|
|
|
* 'widget', 'insert_html', 'insert_image' or 'redirect'. |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $type; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Whether or not to allow additional redirects after redirecting to |
|
24
|
|
|
* destination. Required for changes of type redirect. |
|
25
|
|
|
* @var boolean |
|
26
|
|
|
*/ |
|
27
|
|
|
private $allowAdditionalRedirect; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Indicates whether or not to execute the change asyncronously. |
|
31
|
|
|
* @var boolean |
|
32
|
|
|
*/ |
|
33
|
|
|
private $async; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* CSS selector to determine where changes are applied. Required for changes |
|
37
|
|
|
* of type custom_css, insert_html and insert_image. |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
private $cssSelector; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* A list of dependent change IDs that must happen before this change |
|
44
|
|
|
* @var array[string] |
|
45
|
|
|
*/ |
|
46
|
|
|
private $dependencies; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* URL to redirect to. Required for changes of type redirect. |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
private $destination; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* ID of the extension to insert. Required for changes of type extension. |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
private $extensionId; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Whether or not to preserve parameters from original request when |
|
62
|
|
|
* redirecting to new destination URL. Required for changes of type redirect. |
|
63
|
|
|
* @var boolean |
|
64
|
|
|
*/ |
|
65
|
|
|
private $preserveParameters; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* The Page ID to apply changes to |
|
69
|
|
|
* @var string |
|
70
|
|
|
*/ |
|
71
|
|
|
private $src; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* The value for the change |
|
75
|
|
|
* @var string |
|
76
|
|
|
*/ |
|
77
|
|
|
private $value; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* The ID of the change |
|
81
|
|
|
* @var integer |
|
82
|
|
|
*/ |
|
83
|
|
|
private $id; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Constructor. |
|
87
|
|
|
*/ |
|
88
|
14 |
|
public function __construct($options = array()) |
|
89
|
|
|
{ |
|
90
|
14 |
|
foreach ($options as $name=>$value) { |
|
91
|
|
|
switch ($name) { |
|
92
|
12 |
|
case 'type': $this->setType($value); break; |
|
|
|
|
|
|
93
|
12 |
|
case 'allow_additional_redirect': $this->setAllowAdditionalRedirect($value); break; |
|
|
|
|
|
|
94
|
12 |
|
case 'async': $this->setAsync($value); break; |
|
|
|
|
|
|
95
|
12 |
|
case 'css_selector': $this->setCssSelector($value); break; |
|
|
|
|
|
|
96
|
12 |
|
case 'dependencies': $this->setDependencies($value); break; |
|
|
|
|
|
|
97
|
12 |
|
case 'destination': $this->setDestination($value); break; |
|
|
|
|
|
|
98
|
12 |
|
case 'extension_id': $this->setExtensionId($value); break; |
|
|
|
|
|
|
99
|
12 |
|
case 'preserve_parameters': $this->setPreserveParameters($value); break; |
|
|
|
|
|
|
100
|
12 |
|
case 'src': $this->setSrc($value); break; |
|
|
|
|
|
|
101
|
12 |
|
case 'value': $this->setValue($value); break; |
|
|
|
|
|
|
102
|
8 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
|
|
103
|
|
|
default: |
|
104
|
|
|
throw new \Exception('Unknown option: ' . $name); |
|
105
|
|
|
} |
|
106
|
14 |
|
} |
|
107
|
14 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Returns this object as array. |
|
111
|
|
|
*/ |
|
112
|
6 |
|
public function toArray() |
|
113
|
|
|
{ |
|
114
|
|
|
$options = array( |
|
115
|
6 |
|
'type' => $this->getType(), |
|
116
|
6 |
|
'allow_additional_redirect' => $this->getAllowAdditionalRedirect(), |
|
117
|
6 |
|
'async' => $this->getAsync(), |
|
118
|
6 |
|
'css_selector' => $this->getCssSelector(), |
|
119
|
6 |
|
'dependencies' => $this->getDependencies(), |
|
120
|
6 |
|
'destination' => $this->getDestination(), |
|
121
|
6 |
|
'extension_id' => $this->getExtensionId(), |
|
122
|
6 |
|
'preserve_parameters' => $this->getPreserveParameters(), |
|
123
|
6 |
|
'src' => $this->getSrc(), |
|
124
|
6 |
|
'value' => $this->getValue(), |
|
125
|
6 |
|
'id' => $this->getId(), |
|
126
|
6 |
|
); |
|
127
|
|
|
|
|
128
|
|
|
// Remove options with empty values |
|
129
|
6 |
|
$cleanedOptions = array(); |
|
130
|
6 |
|
foreach ($options as $name=>$value) { |
|
131
|
6 |
|
if ($value!==null) |
|
132
|
6 |
|
$cleanedOptions[$name] = $value; |
|
133
|
6 |
|
} |
|
134
|
|
|
|
|
135
|
6 |
|
return $cleanedOptions; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
7 |
|
public function getType() |
|
139
|
|
|
{ |
|
140
|
7 |
|
return $this->type; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
14 |
|
public function setType($type) |
|
144
|
|
|
{ |
|
145
|
14 |
|
$this->type = $type; |
|
146
|
14 |
|
} |
|
147
|
|
|
|
|
148
|
6 |
|
public function getAllowAdditionalRedirect() |
|
149
|
|
|
{ |
|
150
|
6 |
|
return $this->allowAdditionalRedirect; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
14 |
|
public function setAllowAdditionalRedirect($allowAdditionalRedirect) |
|
154
|
|
|
{ |
|
155
|
14 |
|
$this->allowAdditionalRedirect = $allowAdditionalRedirect; |
|
156
|
14 |
|
} |
|
157
|
|
|
|
|
158
|
6 |
|
public function getAsync() |
|
159
|
|
|
{ |
|
160
|
6 |
|
return $this->async; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
14 |
|
public function setAsync($async) |
|
164
|
|
|
{ |
|
165
|
14 |
|
$this->async = $async; |
|
166
|
14 |
|
} |
|
167
|
|
|
|
|
168
|
6 |
|
public function getCssSelector() |
|
169
|
|
|
{ |
|
170
|
6 |
|
return $this->cssSelector; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
14 |
|
public function setCssSelector($cssSelector) |
|
174
|
|
|
{ |
|
175
|
14 |
|
$this->cssSelector = $cssSelector; |
|
176
|
14 |
|
} |
|
177
|
|
|
|
|
178
|
6 |
|
public function getDependencies() |
|
179
|
|
|
{ |
|
180
|
6 |
|
return $this->dependencies; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
14 |
|
public function setDependencies($dependencies) |
|
184
|
|
|
{ |
|
185
|
14 |
|
$this->dependencies = $dependencies; |
|
186
|
14 |
|
} |
|
187
|
|
|
|
|
188
|
6 |
|
public function getDestination() |
|
189
|
|
|
{ |
|
190
|
6 |
|
return $this->destination; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
14 |
|
public function setDestination($destination) |
|
194
|
|
|
{ |
|
195
|
14 |
|
$this->destination = $destination; |
|
196
|
14 |
|
} |
|
197
|
|
|
|
|
198
|
6 |
|
public function getExtensionId() |
|
199
|
|
|
{ |
|
200
|
6 |
|
return $this->extensionId; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
12 |
|
public function setExtensionId($extensionId) |
|
204
|
|
|
{ |
|
205
|
12 |
|
$this->extensionId = $extensionId; |
|
206
|
12 |
|
} |
|
207
|
|
|
|
|
208
|
6 |
|
public function getPreserveParameters() |
|
209
|
|
|
{ |
|
210
|
6 |
|
return $this->preserveParameters; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
14 |
|
public function setPreserveParameters($preserveParameters) |
|
214
|
|
|
{ |
|
215
|
14 |
|
$this->preserveParameters = $preserveParameters; |
|
216
|
14 |
|
} |
|
217
|
|
|
|
|
218
|
7 |
|
public function getSrc() |
|
219
|
|
|
{ |
|
220
|
7 |
|
return $this->src; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
14 |
|
public function setSrc($src) |
|
224
|
|
|
{ |
|
225
|
14 |
|
$this->src = $src; |
|
226
|
14 |
|
} |
|
227
|
|
|
|
|
228
|
7 |
|
public function getValue() |
|
229
|
|
|
{ |
|
230
|
7 |
|
return $this->value; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
14 |
|
public function setValue($value) |
|
234
|
|
|
{ |
|
235
|
14 |
|
$this->value = $value; |
|
236
|
14 |
|
} |
|
237
|
|
|
|
|
238
|
6 |
|
public function getId() |
|
239
|
|
|
{ |
|
240
|
6 |
|
return $this->id; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
10 |
|
public function setId($id) |
|
244
|
|
|
{ |
|
245
|
10 |
|
$this->id = $id; |
|
246
|
10 |
|
} |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
|
|
250
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
|
|
253
|
|
|
|
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.