Skip to content

Commit 930400f

Browse files
authored
feat(OptimizelyConfig): Add new fields to OptimizelyConfig (#230)
Summary The following new public properties are added to OptimizelyConfig: sdkKey environmentKey attributes audiences events experimentRules and deliveryRules to OptimizelyFeature audiences to OptimizelyExperiment Test plan All FSC tests OPTIMIZELY_CONFIG_V2 tests should pass. https://app.travis-ci.com/github/optimizely/fullstack-sdk-compatibility-suite/builds/235923589
1 parent f15e5f7 commit 930400f

12 files changed

+1324
-115
lines changed

src/Optimizely/Config/DatafileProjectConfig.php

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ class DatafileProjectConfig implements ProjectConfigInterface
9393
*/
9494
private $datafile;
9595

96+
/**
97+
* @var string environmentKey of the config.
98+
*/
99+
private $environmentKey;
100+
101+
/**
102+
* @var string sdkKey of the config.
103+
*/
104+
private $sdkKey;
105+
96106
/**
97107
* @var string Revision of the datafile.
98108
*/
@@ -172,6 +182,34 @@ class DatafileProjectConfig implements ProjectConfigInterface
172182
*/
173183
private $_rollouts;
174184

185+
/**
186+
* list of Attributes that will be parsed from the datafile
187+
*
188+
* @var [Attribute]
189+
*/
190+
private $attributes;
191+
192+
/**
193+
* list of Audiences that will be parsed from the datafile
194+
*
195+
* @var [Audience]
196+
*/
197+
private $audiences;
198+
199+
/**
200+
* list of Events that will be parsed from the datafile
201+
*
202+
* @var [Event]
203+
*/
204+
private $events;
205+
206+
/**
207+
* list of Typed Audiences that will be parsed from the datafile
208+
*
209+
* @var [Audience]
210+
*/
211+
private $typedAudiences;
212+
175213
/**
176214
* internal mapping of feature keys to feature flag models.
177215
*
@@ -222,6 +260,8 @@ public function __construct($datafile, $logger, $errorHandler)
222260
$this->_logger = $logger;
223261
$this->_errorHandler = $errorHandler;
224262
$this->_version = $config['version'];
263+
$this->environmentKey = isset($config['environmentKey']) ? $config['environmentKey'] : '';
264+
$this->sdkKey = isset($config['sdkKey']) ? $config['sdkKey'] : '';
225265
if (!in_array($this->_version, $supportedVersions)) {
226266
throw new InvalidDatafileVersionException(
227267
"This version of the PHP SDK does not support the given datafile version: {$this->_version}."
@@ -237,10 +277,10 @@ public function __construct($datafile, $logger, $errorHandler)
237277

238278
$groups = $config['groups'] ?: [];
239279
$experiments = $config['experiments'] ?: [];
240-
$events = $config['events'] ?: [];
241-
$attributes = $config['attributes'] ?: [];
242-
$audiences = $config['audiences'] ?: [];
243-
$typedAudiences = isset($config['typedAudiences']) ? $config['typedAudiences']: [];
280+
$this->attributes = isset($config['attributes']) ? $config['attributes'] : [];
281+
$this->audiences = isset($config['audiences']) ? $config['audiences'] : [];
282+
$this->events = isset($config['events']) ? $config['events'] : [];
283+
$this->typedAudiences = isset($config['typedAudiences']) ? $config['typedAudiences'] : [];
244284
$rollouts = isset($config['rollouts']) ? $config['rollouts'] : [];
245285
$featureFlags = isset($config['featureFlags']) ? $config['featureFlags']: [];
246286

@@ -258,10 +298,10 @@ public function __construct($datafile, $logger, $errorHandler)
258298

259299
$this->_groupIdMap = ConfigParser::generateMap($groups, 'id', Group::class);
260300
$this->_experimentIdMap = ConfigParser::generateMap($experiments, 'id', Experiment::class);
261-
$this->_eventKeyMap = ConfigParser::generateMap($events, 'key', Event::class);
262-
$this->_attributeKeyMap = ConfigParser::generateMap($attributes, 'key', Attribute::class);
263-
$typedAudienceIdMap = ConfigParser::generateMap($typedAudiences, 'id', Audience::class);
264-
$this->_audienceIdMap = ConfigParser::generateMap($audiences, 'id', Audience::class);
301+
$this->_eventKeyMap = ConfigParser::generateMap($this->events, 'key', Event::class);
302+
$this->_attributeKeyMap = ConfigParser::generateMap($this->attributes, 'key', Attribute::class);
303+
$typedAudienceIdMap = ConfigParser::generateMap($this->typedAudiences, 'id', Audience::class);
304+
$this->_audienceIdMap = ConfigParser::generateMap($this->audiences, 'id', Audience::class);
265305
$this->_rollouts = ConfigParser::generateMap($rollouts, null, Rollout::class);
266306
$this->_featureFlags = ConfigParser::generateMap($featureFlags, null, FeatureFlag::class);
267307

@@ -449,6 +489,22 @@ public function getRevision()
449489
return $this->_revision;
450490
}
451491

492+
/**
493+
* @return string Config environmentKey.
494+
*/
495+
public function getEnvironmentKey()
496+
{
497+
return $this->environmentKey;
498+
}
499+
500+
/**
501+
* @return string Config sdkKey.
502+
*/
503+
public function getSdkKey()
504+
{
505+
return $this->sdkKey;
506+
}
507+
452508
/**
453509
* @return array List of feature flags parsed from the datafile
454510
*/
@@ -457,6 +513,38 @@ public function getFeatureFlags()
457513
return $this->_featureFlags;
458514
}
459515

516+
/**
517+
* @return array List of attributes parsed from the datafile
518+
*/
519+
public function getAttributes()
520+
{
521+
return $this->attributes;
522+
}
523+
524+
/**
525+
* @return array List of audiences parsed from the datafile
526+
*/
527+
public function getAudiences()
528+
{
529+
return $this->audiences;
530+
}
531+
532+
/**
533+
* @return array List of events parsed from the datafile
534+
*/
535+
public function getEvents()
536+
{
537+
return $this->events;
538+
}
539+
540+
/**
541+
* @return array List of typed audiences parsed from the datafile
542+
*/
543+
public function getTypedAudiences()
544+
{
545+
return $this->typedAudiences;
546+
}
547+
460548
/**
461549
* @return array List of all experiments (including group experiments)
462550
* parsed from the datafile
@@ -470,7 +558,7 @@ public function getAllExperiments()
470558
$rolloutExperimentIds[] = $experiment->getId();
471559
}
472560
}
473-
return array_filter(array_values($this->_experimentKeyMap), function ($experiment) use ($rolloutExperimentIds) {
561+
return array_filter(array_values($this->_experimentIdMap), function ($experiment) use ($rolloutExperimentIds) {
474562
return !in_array($experiment->getId(), $rolloutExperimentIds);
475563
});
476564
}

src/Optimizely/Config/ProjectConfigInterface.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@ public function getBotFiltering();
5151
*/
5252
public function getRevision();
5353

54+
/**
55+
* @return string String representing environment key of the datafile.
56+
*/
57+
public function getEnvironmentKey();
58+
59+
/**
60+
* @return string String representing sdkkey of the datafile.
61+
*/
62+
public function getSdkKey();
63+
64+
/**
65+
* @return array List of attributes parsed from the datafile
66+
*/
67+
public function getAttributes();
68+
69+
/**
70+
* @return array List of audiences parsed from the datafile
71+
*/
72+
public function getAudiences();
73+
74+
/**
75+
* @return array List of events parsed from the datafile
76+
*/
77+
public function getEvents();
78+
79+
/**
80+
* @return array List of typed audiences parsed from the datafile
81+
*/
82+
public function getTypedAudiences();
83+
84+
5485
/**
5586
* @return array List of feature flags parsed from the datafile
5687
*/
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright 2021, Optimizely Inc and Contributors
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+
namespace Optimizely\OptimizelyConfig;
18+
19+
class OptimizelyAttribute implements \JsonSerializable
20+
{
21+
/**
22+
* @var string id representing attribute.
23+
*/
24+
private $id;
25+
26+
/**
27+
* @var string key representing attribute.
28+
*/
29+
private $key;
30+
31+
public function __construct($id, $key)
32+
{
33+
$this->id = $id;
34+
$this->key = $key;
35+
}
36+
37+
/**
38+
* @return string attribute id.
39+
*/
40+
public function getId()
41+
{
42+
return $this->id;
43+
}
44+
45+
/**
46+
* @return string attribute key.
47+
*/
48+
public function getKey()
49+
{
50+
return $this->key;
51+
}
52+
53+
/**
54+
* @return string JSON representation of the object.
55+
*/
56+
public function jsonSerialize()
57+
{
58+
return get_object_vars($this);
59+
}
60+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright 2021, Optimizely Inc and Contributors
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+
namespace Optimizely\OptimizelyConfig;
18+
19+
class OptimizelyAudience implements \JsonSerializable
20+
{
21+
/**
22+
* @var string representing audience id.
23+
*/
24+
private $id;
25+
26+
/**
27+
* @var string representing audience name .
28+
*/
29+
private $name;
30+
31+
/**
32+
* @var string conditions representing audience conditions.
33+
*/
34+
private $conditions;
35+
36+
37+
public function __construct($id, $name, $conditions)
38+
{
39+
$this->id = $id;
40+
$this->name = $name;
41+
$this->conditions = $conditions;
42+
}
43+
44+
/**
45+
* @return string audience id.
46+
*/
47+
public function getId()
48+
{
49+
return $this->id;
50+
}
51+
52+
/**
53+
* @return string audience name.
54+
*/
55+
public function getName()
56+
{
57+
return $this->name;
58+
}
59+
60+
/**
61+
* @return string audience conditions.
62+
*/
63+
public function getConditions()
64+
{
65+
return $this->conditions;
66+
}
67+
68+
/**
69+
* @return string JSON representation of the object.
70+
*/
71+
public function jsonSerialize()
72+
{
73+
return get_object_vars($this);
74+
}
75+
}

0 commit comments

Comments
 (0)