|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
|
4
|
|
|
* @date 04 May 2017 |
|
5
|
|
|
* @copyright (c) 2017, Web Marketing ROI |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
|
8
|
|
|
|
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Exception; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* An Optimizely campaign change attributes. |
|
13
|
|
|
*/ |
|
14
|
|
|
class ChangeAttribute |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Name of the class to set the element(s) matched by a selector to |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $class; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Whether or not to hide the element(s) matched by a selector |
|
24
|
|
|
* @var boolean |
|
25
|
|
|
*/ |
|
26
|
|
|
private $hide; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Value of href attribute to add to element(s) matched by a selector |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
private $href; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Value of HTML attribute to add to element(s) matched by a selector |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $html; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Whether or not to remove the element(s) matched by a selector |
|
42
|
|
|
* @var boolean |
|
43
|
|
|
*/ |
|
44
|
|
|
private $remove; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Value of src attribute to add to element(s) matched by a selector |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
private $src; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Value of style attribute to add to element(s) matched by a selector |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
private $style; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Value of text attribute to add to the element(s) matched by a selector |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
private $text; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Constructor. |
|
66
|
|
|
*/ |
|
67
|
3 |
|
public function __construct($options = array()) |
|
68
|
|
|
{ |
|
69
|
3 |
|
foreach ($options as $name=>$value) { |
|
70
|
|
|
switch ($name) { |
|
71
|
3 |
|
case 'class': $this->setClass($value); break; |
|
|
|
|
|
|
72
|
3 |
|
case 'hide': $this->setHide($value); break; |
|
|
|
|
|
|
73
|
3 |
|
case 'href': $this->setHref($value); break; |
|
|
|
|
|
|
74
|
3 |
|
case 'html': $this->setHtml($value); break; |
|
|
|
|
|
|
75
|
3 |
|
case 'remove': $this->setRemove($value); break; |
|
|
|
|
|
|
76
|
3 |
|
case 'src': $this->setSrc($value); break; |
|
|
|
|
|
|
77
|
3 |
|
case 'style': $this->setStyle($value); break; |
|
|
|
|
|
|
78
|
3 |
|
case 'text': $this->setText($value); break; |
|
|
|
|
|
|
79
|
|
|
default: |
|
80
|
|
|
throw new Exception('Unknown option found in the ChangeAttribute entity: ' . $name); |
|
81
|
|
|
} |
|
82
|
3 |
|
} |
|
83
|
3 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns this object as array. |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function toArray() |
|
89
|
|
|
{ |
|
90
|
|
|
$options = array( |
|
91
|
1 |
|
'class' => $this->getClass(), |
|
92
|
1 |
|
'hide' => $this->getHide(), |
|
93
|
1 |
|
'href' => $this->getHref(), |
|
94
|
1 |
|
'html' => $this->getHtml(), |
|
95
|
1 |
|
'remove' => $this->getRemove(), |
|
96
|
1 |
|
'src' => $this->getSrc(), |
|
97
|
1 |
|
'style' => $this->getStyle(), |
|
98
|
1 |
|
'text' => $this->getText(), |
|
99
|
1 |
|
); |
|
100
|
|
|
|
|
101
|
|
|
// Remove options with empty values |
|
102
|
1 |
|
$cleanedOptions = array(); |
|
103
|
1 |
|
foreach ($options as $name=>$value) { |
|
104
|
1 |
|
if ($value!==null) |
|
105
|
1 |
|
$cleanedOptions[$name] = $value; |
|
106
|
1 |
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
return $cleanedOptions; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
2 |
|
public function getClass() |
|
112
|
|
|
{ |
|
113
|
2 |
|
return $this->class; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
3 |
|
public function setClass($class) |
|
117
|
|
|
{ |
|
118
|
3 |
|
$this->class = $class; |
|
119
|
3 |
|
} |
|
120
|
|
|
|
|
121
|
2 |
|
public function getHide() |
|
122
|
|
|
{ |
|
123
|
2 |
|
return $this->hide; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
3 |
|
public function setHide($hide) |
|
127
|
|
|
{ |
|
128
|
3 |
|
$this->hide = $hide; |
|
129
|
3 |
|
} |
|
130
|
|
|
|
|
131
|
1 |
|
public function getHref() |
|
132
|
|
|
{ |
|
133
|
1 |
|
return $this->href; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
3 |
|
public function setHref($href) |
|
137
|
|
|
{ |
|
138
|
3 |
|
$this->href = $href; |
|
139
|
3 |
|
} |
|
140
|
|
|
|
|
141
|
1 |
|
public function getHtml() |
|
142
|
|
|
{ |
|
143
|
1 |
|
return $this->html; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
3 |
|
public function setHtml($html) |
|
147
|
|
|
{ |
|
148
|
3 |
|
$this->html = $html; |
|
149
|
3 |
|
} |
|
150
|
|
|
|
|
151
|
1 |
|
public function getRemove() |
|
152
|
|
|
{ |
|
153
|
1 |
|
return $this->remove; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
3 |
|
public function setRemove($remove) |
|
157
|
|
|
{ |
|
158
|
3 |
|
$this->remove = $remove; |
|
159
|
3 |
|
} |
|
160
|
|
|
|
|
161
|
1 |
|
public function getSrc() |
|
162
|
|
|
{ |
|
163
|
1 |
|
return $this->src; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
3 |
|
public function setSrc($src) |
|
167
|
|
|
{ |
|
168
|
3 |
|
$this->src = $src; |
|
169
|
3 |
|
} |
|
170
|
|
|
|
|
171
|
1 |
|
public function getStyle() |
|
172
|
|
|
{ |
|
173
|
1 |
|
return $this->style; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
3 |
|
public function setStyle($style) |
|
177
|
|
|
{ |
|
178
|
3 |
|
$this->style = $style; |
|
179
|
3 |
|
} |
|
180
|
|
|
|
|
181
|
1 |
|
public function getText() |
|
182
|
|
|
{ |
|
183
|
1 |
|
return $this->text; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
3 |
|
public function setText($text) |
|
187
|
|
|
{ |
|
188
|
3 |
|
$this->text = $text; |
|
189
|
3 |
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
|
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.