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 CSS attribute. |
13
|
|
|
*/ |
14
|
|
|
class CssAttribute |
15
|
|
|
{ |
16
|
|
|
private $backgroundColor; |
17
|
|
|
|
18
|
|
|
private $backgroundImage; |
19
|
|
|
|
20
|
|
|
private $borderColor; |
21
|
|
|
|
22
|
|
|
private $borderStyle; |
23
|
|
|
|
24
|
|
|
private $borderWidth; |
25
|
|
|
|
26
|
|
|
private $color; |
27
|
|
|
|
28
|
|
|
private $fontSize; |
29
|
|
|
|
30
|
|
|
private $fontWeight; |
31
|
|
|
|
32
|
|
|
private $height; |
33
|
|
|
|
34
|
|
|
private $position; |
35
|
|
|
|
36
|
|
|
private $width; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Constructor. |
40
|
|
|
*/ |
41
|
|
|
public function __construct($options = array()) |
42
|
|
|
{ |
43
|
|
|
foreach ($options as $name=>$value) { |
44
|
|
|
switch ($name) { |
45
|
|
|
case 'background-color': $this->setBackgroundColor($value); break; |
46
|
|
|
case 'background-image': $this->setBackgroundImage($value); break; |
47
|
|
|
case 'border-color': $this->setBorderColor($value); break; |
48
|
|
|
case 'border-style': $this->setBorderStyle($value); break; |
49
|
|
|
case 'border-width': $this->setBorderWidth($value); break; |
50
|
|
|
case 'color': $this->setColor($value); break; |
51
|
|
|
case 'font-size': $this->setFontSize($value); break; |
52
|
|
|
case 'font-weight': $this->setFontWeight($value); break; |
53
|
|
|
case 'height': $this->setHeight($value); break; |
54
|
|
|
case 'position': $this->setPosition($value); break; |
55
|
|
|
case 'width': $this->setWidth($value); break; |
56
|
|
|
default: |
57
|
|
|
throw new Exception('Unknown option found in the CssAttribute entity: ' . $name); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns this object as array. |
64
|
|
|
*/ |
65
|
|
|
public function toArray() |
66
|
|
|
{ |
67
|
|
|
$options = array( |
68
|
|
|
'background-color' => $this->getBackgroundColor(), |
69
|
|
|
'background-image' => $this->getBackgroundImage(), |
70
|
|
|
'border-color' => $this->getBorderColor(), |
71
|
|
|
'border-style' => $this->getBorderStyle(), |
72
|
|
|
'border-width' => $this->getBorderWidth(), |
73
|
|
|
'color' => $this->getColor(), |
74
|
|
|
'font-size' => $this->getFontSize(), |
75
|
|
|
'font-weight' => $this->getFontWeight(), |
76
|
|
|
'height' => $this->getHeight(), |
77
|
|
|
'position' => $this->getPosition(), |
78
|
|
|
'width' => $this->getWidth(), |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
// Remove options with empty values |
82
|
|
|
$cleanedOptions = array(); |
83
|
|
|
foreach ($options as $name=>$value) { |
84
|
|
|
if ($value!==null) |
85
|
|
|
$cleanedOptions[$name] = $value; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $cleanedOptions; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getBackgroundColor() |
92
|
|
|
{ |
93
|
|
|
return $this->backgroundColor; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setBackgroundColor($backgroundColor) |
97
|
|
|
{ |
98
|
|
|
$this->backgroundColor = $backgroundColor; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getBackgroundImage() |
102
|
|
|
{ |
103
|
|
|
return $this->backgroundImage; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setBackgroundImage($backgroundImage) |
107
|
|
|
{ |
108
|
|
|
$this->backgroundImage = $backgroundImage; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getBorderColor() |
112
|
|
|
{ |
113
|
|
|
return $this->borderColor; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function setBorderColor($borderColor) |
117
|
|
|
{ |
118
|
|
|
$this->borderColor = $borderColor; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getBorderStyle() |
122
|
|
|
{ |
123
|
|
|
return $this->borderStyle; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function setBorderStyle($borderStyle) |
127
|
|
|
{ |
128
|
|
|
$this->borderStyle = $borderStyle; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getBorderWidth() |
132
|
|
|
{ |
133
|
|
|
return $this->borderWidth; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function setBorderWidth($borderWidth) |
137
|
|
|
{ |
138
|
|
|
$this->borderWidth = $borderWidth; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function getColor() |
142
|
|
|
{ |
143
|
|
|
return $this->color; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function setColor($color) |
147
|
|
|
{ |
148
|
|
|
$this->color = $color; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function getFontSize() |
152
|
|
|
{ |
153
|
|
|
return $this->fontSize; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function setFontSize($fontSize) |
157
|
|
|
{ |
158
|
|
|
$this->fontSize = $fontSize; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function getFontWeight() |
162
|
|
|
{ |
163
|
|
|
return $this->fontWeight; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function setFontWeight($fontWeight) |
167
|
|
|
{ |
168
|
|
|
$this->fontWeight = $fontWeight; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function getHeight() |
172
|
|
|
{ |
173
|
|
|
return $this->height; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function setHeight($height) |
177
|
|
|
{ |
178
|
|
|
$this->height = $height; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function getPosition() |
182
|
|
|
{ |
183
|
|
|
return $this->position; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function setPosition($position) |
187
|
|
|
{ |
188
|
|
|
$this->position = $position; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function getWidth() |
192
|
|
|
{ |
193
|
|
|
return $this->width; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function setWidth($width) |
197
|
|
|
{ |
198
|
|
|
$this->width = $width; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
|
203
|
|
|
|
204
|
|
|
|
205
|
|
|
|
206
|
|
|
|
207
|
|
|
|
208
|
|
|
|