Skip to content

Commit f47243a

Browse files
oakbaniwangjoshuah
authored andcommitted
Feature Flags Models and Parsing from new v4 data file (#68)
* Feature Flags models and parsing from new v4 file
1 parent e60d1c5 commit f47243a

File tree

17 files changed

+1437
-315
lines changed

17 files changed

+1437
-315
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* Copyright 2017, Optimizely
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Optimizely\Entity;
19+
20+
use Optimizely\Utils\ConfigParser;
21+
22+
class FeatureFlag{
23+
24+
/**
25+
* variable to hold feature flag ID
26+
* @var String
27+
*/
28+
private $_id;
29+
30+
/**
31+
* variable to hold feature flag key
32+
* @var String
33+
*/
34+
private $_key;
35+
36+
/**
37+
* The ID of the rollout that is attached to this feature flag
38+
* @var String
39+
*/
40+
private $_rolloutId;
41+
42+
/**
43+
* A list of the IDs of the experiments the feature flag is attached to. If there are multiple expeirments,
44+
* they must be in the same mutually exclusive group.
45+
* @var [String]
46+
*/
47+
private $_experimentIds;
48+
49+
/**
50+
* A list of the feature variables that are part of this feature
51+
* @var [FeatureVariable]
52+
*/
53+
private $_variables;
54+
55+
public function __construct($id = null, $key = null, $rolloutId = null, $experimentIds = null, $variables = []){
56+
$this->_id = $id;
57+
$this->_key = $key;
58+
$this->_rolloutId = $rolloutId;
59+
$this->_experimentIds = $experimentIds;
60+
$this->_variables = ConfigParser::generateMap($variables, null, FeatureVariable::class);
61+
}
62+
63+
/**
64+
* @return String feature flag ID
65+
*/
66+
public function getId(){
67+
return $this->_id;
68+
}
69+
70+
/**
71+
* @param String $id feature flag ID
72+
*/
73+
public function setId($id){
74+
$this->_id = $id;
75+
}
76+
77+
/**
78+
* @return String feature flag key
79+
*/
80+
public function getKey(){
81+
return $this->_key;
82+
}
83+
84+
/**
85+
* @param String $key feature flag key
86+
*/
87+
public function setKey($key){
88+
$this->_key = $key;
89+
}
90+
91+
/**
92+
* @return String attached rollout ID
93+
*/
94+
public function getRolloutId(){
95+
return $this->_rolloutId;
96+
}
97+
98+
/**
99+
* @param String $rolloutId attached rollout ID
100+
*/
101+
public function setRolloutId($rolloutId){
102+
$this->_rolloutId = $rolloutId;
103+
}
104+
105+
/**
106+
* @return [String] attached experiment IDs
107+
*/
108+
public function getExperimentIds(){
109+
return $this->_experimentIds;
110+
}
111+
112+
/**
113+
* @param [String] $experimentIds attached experiment IDs
114+
*/
115+
public function setExperimentIds($experimentIds){
116+
$this->_experimentIds = $experimentIds;
117+
}
118+
119+
/**
120+
* @return [FeatureVariable] feature variables that are part of this feature
121+
*/
122+
public function getVariables(){
123+
return $this->_variables;
124+
}
125+
126+
/**
127+
* @param [FeatureVariable] $variables feature variables that are part of this feature
128+
*/
129+
public function setVariables($variables){
130+
$this->_variables = ConfigParser::generateMap($variables, null, FeatureVariable::class);
131+
}
132+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/**
3+
* Copyright 2017, Optimizely
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Optimizely\Entity;
19+
20+
class FeatureVariable{
21+
22+
// Feature variable primitive types
23+
const BOOLEAN_TYPE = 'boolean';
24+
const STRING_TYPE = 'string';
25+
const INTEGER_TYPE = 'integer';
26+
CONST DOUBLE_TYPE = 'double';
27+
28+
/**
29+
* variable to hold the feature variable ID
30+
* @var String
31+
*/
32+
private $_id;
33+
34+
/**
35+
* variable to hold the feature variable key
36+
* @var String
37+
*/
38+
private $_key;
39+
40+
/**
41+
* variable denoting what primitive type the variable is. Will be one of 4 possible values:
42+
* a. boolean
43+
* b. string
44+
* c. integer
45+
* d. double
46+
* @var String
47+
*/
48+
private $_type;
49+
50+
/**
51+
* variable containing the string representation of the default value for the feature variable.
52+
* This is the variable value that should be returned if the user is not bucketed into any variations
53+
* or fails the audience rules.
54+
* @var String
55+
*/
56+
private $_defaultValue;
57+
58+
59+
public function __construct($id =null, $key = null, $type = null, $defaultValue = null){
60+
$this->_id = $id;
61+
$this->_key = $key;
62+
$this->_type = $type;
63+
$this->_defaultValue = $defaultValue;
64+
}
65+
66+
/**
67+
* @return String Feature variable ID
68+
*/
69+
public function getId(){
70+
return $this->_id;
71+
}
72+
73+
/**
74+
* @param String $id Feature variable ID
75+
*/
76+
public function setId($id){
77+
$this->_id = $id;
78+
}
79+
80+
/**
81+
* @return String Feature variable Key
82+
*/
83+
public function getKey(){
84+
return $this->_key;
85+
}
86+
87+
/**
88+
* @param String $key Feature variable Key
89+
*/
90+
public function setKey($key){
91+
$this->_key = $key;
92+
}
93+
94+
/**
95+
* @return String Feature variable primitive type
96+
*/
97+
public function getType(){
98+
return $this->_type;
99+
}
100+
101+
/**
102+
* @param String $type Feature variable primitive type
103+
*/
104+
public function setType($type){
105+
$this->_type = $type;
106+
}
107+
108+
/**
109+
* @return String Default value of the feature variable
110+
*/
111+
public function getDefaultValue(){
112+
return $this->_defaultValue;
113+
}
114+
115+
/**
116+
* @param String $value Default value of the feature variable
117+
*/
118+
public function setDefaultValue($value){
119+
$this->_defaultValue = $value;
120+
}
121+
}

src/Optimizely/Entity/Rollout.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright 2017, Optimizely
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Optimizely\Entity;
19+
20+
use Optimizely\Utils\ConfigParser;
21+
22+
class Rollout{
23+
24+
/**
25+
* The ID of the rollout
26+
* @var String
27+
*/
28+
private $_id;
29+
30+
/**
31+
* A list of experiments representing the different rules of the rollout
32+
* @var [Experiment]
33+
*/
34+
private $_experiments;
35+
36+
public function __construct($id = null, $experiments = []){
37+
$this->_id = $id;
38+
$this->_experiments = ConfigParser::generateMap($experiments, null, Experiment::class);
39+
}
40+
41+
/**
42+
* @return String ID of the rollout
43+
*/
44+
public function getId(){
45+
return $this->_id;
46+
}
47+
48+
/**
49+
* @param String $id ID of the rollout
50+
*/
51+
public function setId($id){
52+
$this->_id = $id;
53+
}
54+
55+
/**
56+
* @return [Experiments] A list of experiments representing the different rules of the rollout
57+
*/
58+
public function getExperiments(){
59+
return $this->_experiments;
60+
}
61+
62+
/**
63+
* @param [Experiments] $experiments A list of experiments representing the different rules of the rollout
64+
*/
65+
public function setExperiments($experiments){
66+
$this->_experiments = ConfigParser::generateMap($experiments, null, Experiment::class);
67+
}
68+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright 2017, Optimizely
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Optimizely\Entity;
19+
20+
class VariableUsage{
21+
22+
/**
23+
* The ID of the live variable this usage is modifying
24+
* @var String
25+
*/
26+
private $_id;
27+
28+
/**
29+
* the variable value for users in this particular variation
30+
* @var String
31+
*/
32+
private $_value;
33+
34+
public function __construct($id = null, $value = null){
35+
$this->_id = $id;
36+
$this->_value = $value;
37+
}
38+
39+
/**
40+
* @return String ID of the live variable this usage is modifying
41+
*/
42+
public function getId(){
43+
return $this->_id;
44+
}
45+
46+
/**
47+
* @param String $id ID of the live variable this usage is modifying
48+
*/
49+
public function setId($id){
50+
$this->_id = $id;
51+
}
52+
53+
/**
54+
* @return String variable value for users in this particular variation
55+
*/
56+
public function getValue(){
57+
return $this->_value;
58+
}
59+
60+
/**
61+
* @param String $value variable value for users in this particular variation
62+
*/
63+
public function setValue($value){
64+
$this->_value = $value;
65+
}
66+
}

0 commit comments

Comments
 (0)