Skip to content

Commit d0c5f4e

Browse files
oakbanimikeproeng37
authored andcommitted
Is Feature Enabled and Feature Variable Accessor APIs (#71)
1 parent afa7a55 commit d0c5f4e

File tree

10 files changed

+1369
-179
lines changed

10 files changed

+1369
-179
lines changed

src/Optimizely/Entity/Variation.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ public function __construct($id = null, $key = null, $variableUsageInstances = [
5252

5353
$this->_variableUsageInstances = ConfigParser::generateMap($variableUsageInstances, null, VariableUsage::class);
5454

55-
if(!empty($this->_variableUsageInstances)){
56-
foreach(array_values($this->_variableUsageInstances) as $variableUsage){
57-
$_variableIdToVariableUsageInstanceMap[$variableUsage->getId()] = $variableUsage;
58-
}
59-
}
55+
$this->generateVariableIdToVariableUsageMap();
6056
}
6157

6258
/**
@@ -91,16 +87,41 @@ public function setKey($key)
9187
$this->_key = $key;
9288
}
9389

90+
/**
91+
* @return [VariableUsage] Variable usage instances in this variation
92+
*/
9493
public function getVariables(){
9594
return $this->_variableUsageInstances;
9695
}
9796

97+
/**
98+
* @param string Variable ID
99+
*
100+
* @return VariableUsage Variable usage instance corresponding to given variable ID
101+
*/
102+
public function getVariableUsageById($variableId){
103+
if(isset($this->_variableIdToVariableUsageInstanceMap[$variableId]))
104+
return $this->_variableIdToVariableUsageInstanceMap[$variableId];
105+
else
106+
return null;
107+
}
108+
109+
/**
110+
* @param [VariableUsage] array of variable usage instances
111+
*/
98112
public function setVariables($variableUsageInstances){
99113
$this->_variableUsageInstances = ConfigParser::generateMap($variableUsageInstances, null , VariableUsage::class);
114+
$this->generateVariableIdToVariableUsageMap();
115+
}
100116

117+
/**
118+
* Generates variable ID to Variable usage instance map
119+
* from variable usage instances
120+
*/
121+
private function generateVariableIdToVariableUsageMap(){
101122
if(!empty($this->_variableUsageInstances)){
102123
foreach(array_values($this->_variableUsageInstances) as $variableUsage){
103-
$_variableIdToVariableUsageInstanceMap[$variableUsage->getId()] = $variableUsage;
124+
$this->_variableIdToVariableUsageInstanceMap[$variableUsage->getId()] = $variableUsage;
104125
}
105126
}
106127
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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\Exceptions;
19+
20+
21+
class InvalidFeatureVariableException extends OptimizelyException
22+
{
23+
}

0 commit comments

Comments
 (0)