1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 05 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
|
|
|
* Optimizely attribute. |
13
|
|
|
*/ |
14
|
|
|
class Attribute |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Unique string identifier for this Attribute within the project |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $key; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The ID of the project the Attribute belongs to |
24
|
|
|
* @var integer |
25
|
|
|
*/ |
26
|
|
|
private $projectId; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Whether or not the Attribute has been archived |
30
|
|
|
* @var boolean |
31
|
|
|
*/ |
32
|
|
|
private $archived; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* A short description of the Attribute |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $description; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The name of the Attribute |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $name; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Whether this Attribute is a custom dimension or custom attribute. If this |
48
|
|
|
* is a custom dimension, it belongs to an Optimizely Classic experiment and |
49
|
|
|
* is read-only. |
50
|
|
|
* Can be custom_attribute or custom_dimension |
51
|
|
|
*/ |
52
|
|
|
private $conditionType; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* The unique identifier for the Attribute |
56
|
|
|
* @var integer |
57
|
|
|
*/ |
58
|
|
|
private $id; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The last time the Attribute was modified |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
private $lastModified; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Constructor. |
68
|
|
|
*/ |
69
|
7 |
|
public function __construct($options = array()) |
70
|
|
|
{ |
71
|
7 |
|
foreach ($options as $name=>$value) { |
72
|
|
|
switch ($name) { |
73
|
6 |
|
case 'key': $this->setKey($value); break; |
|
|
|
|
74
|
6 |
|
case 'project_id': $this->setProjectId($value); break; |
|
|
|
|
75
|
6 |
|
case 'archived': $this->setArchived($value); break; |
|
|
|
|
76
|
6 |
|
case 'description': $this->setDescription($value); break; |
|
|
|
|
77
|
6 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
78
|
6 |
|
case 'condition_type': $this->setConditionType($value); break; |
|
|
|
|
79
|
6 |
|
case 'id': $this->setId($value); break; |
|
|
|
|
80
|
6 |
|
case 'last_modified': $this->setLastModified($value); break; |
|
|
|
|
81
|
|
|
default: |
82
|
|
|
throw new Exception('Unknown option found in the Attribute entity: ' . $name); |
83
|
|
|
} |
84
|
7 |
|
} |
85
|
7 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns this object as array. |
89
|
|
|
*/ |
90
|
3 |
|
public function toArray() |
91
|
|
|
{ |
92
|
|
|
$options = array( |
93
|
3 |
|
'key' => $this->getKey(), |
94
|
3 |
|
'project_id' => $this->getProjectId(), |
95
|
3 |
|
'archived' => $this->getArchived(), |
96
|
3 |
|
'description' => $this->getDescription(), |
97
|
3 |
|
'name' => $this->getName(), |
98
|
3 |
|
'condition_type' => $this->getConditionType(), |
99
|
3 |
|
'id' => $this->getId(), |
100
|
3 |
|
'last_modified' => $this->getLastModified(), |
101
|
3 |
|
); |
102
|
|
|
|
103
|
|
|
// Remove options with empty values |
104
|
3 |
|
$cleanedOptions = array(); |
105
|
3 |
|
foreach ($options as $name=>$value) { |
106
|
3 |
|
if ($value!==null) |
107
|
3 |
|
$cleanedOptions[$name] = $value; |
108
|
3 |
|
} |
109
|
|
|
|
110
|
3 |
|
return $cleanedOptions; |
111
|
|
|
} |
112
|
|
|
|
113
|
5 |
|
public function getKey() |
114
|
|
|
{ |
115
|
5 |
|
return $this->key; |
116
|
|
|
} |
117
|
|
|
|
118
|
7 |
|
public function setKey($key) |
119
|
|
|
{ |
120
|
7 |
|
$this->key = $key; |
121
|
7 |
|
} |
122
|
|
|
|
123
|
5 |
|
public function getProjectId() |
124
|
|
|
{ |
125
|
5 |
|
return $this->projectId; |
126
|
|
|
} |
127
|
|
|
|
128
|
7 |
|
public function setProjectId($projectId) |
129
|
|
|
{ |
130
|
7 |
|
$this->projectId = $projectId; |
131
|
7 |
|
} |
132
|
|
|
|
133
|
5 |
|
public function getArchived() |
134
|
|
|
{ |
135
|
5 |
|
return $this->archived; |
136
|
|
|
} |
137
|
|
|
|
138
|
7 |
|
public function setArchived($archived) |
139
|
|
|
{ |
140
|
7 |
|
$this->archived = $archived; |
141
|
7 |
|
} |
142
|
|
|
|
143
|
5 |
|
public function getDescription() |
144
|
|
|
{ |
145
|
5 |
|
return $this->description; |
146
|
|
|
} |
147
|
|
|
|
148
|
7 |
|
public function setDescription($description) |
149
|
|
|
{ |
150
|
7 |
|
$this->description = $description; |
151
|
7 |
|
} |
152
|
|
|
|
153
|
7 |
|
public function getName() |
154
|
|
|
{ |
155
|
7 |
|
return $this->name; |
156
|
|
|
} |
157
|
|
|
|
158
|
7 |
|
public function setName($name) |
159
|
|
|
{ |
160
|
7 |
|
$this->name = $name; |
161
|
7 |
|
} |
162
|
|
|
|
163
|
5 |
|
public function getConditionType() |
164
|
|
|
{ |
165
|
5 |
|
return $this->conditionType; |
166
|
|
|
} |
167
|
|
|
|
168
|
7 |
|
public function setConditionType($conditionType) |
169
|
|
|
{ |
170
|
7 |
|
$this->conditionType = $conditionType; |
171
|
7 |
|
} |
172
|
|
|
|
173
|
5 |
|
public function getId() |
174
|
|
|
{ |
175
|
5 |
|
return $this->id; |
176
|
|
|
} |
177
|
|
|
|
178
|
7 |
|
public function setId($id) |
179
|
|
|
{ |
180
|
7 |
|
$this->id = $id; |
181
|
7 |
|
} |
182
|
|
|
|
183
|
5 |
|
public function getLastModified() |
184
|
|
|
{ |
185
|
5 |
|
return $this->lastModified; |
186
|
|
|
} |
187
|
|
|
|
188
|
7 |
|
public function setLastModified($lastModified) |
189
|
|
|
{ |
190
|
7 |
|
$this->lastModified = $lastModified; |
191
|
7 |
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
|
196
|
|
|
|
197
|
|
|
|
198
|
|
|
|
199
|
|
|
|
200
|
|
|
|
201
|
|
|
|
202
|
|
|
|
203
|
|
|
|
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.