-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(OptimizelyConfig): Add new fields to OptimizelyConfig #230
Changes from 3 commits
df67724
c56a186
4176c4b
b67e2d1
563003b
ccda595
1df4ab0
8d23eeb
5304778
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,16 @@ class DatafileProjectConfig implements ProjectConfigInterface | |
*/ | ||
private $datafile; | ||
|
||
/** | ||
* @var string environmentKey of the config. | ||
*/ | ||
private $environmentKey; | ||
|
||
/** | ||
* @var string sdkKey of the config. | ||
*/ | ||
private $sdkKey; | ||
|
||
/** | ||
* @var string Revision of the datafile. | ||
*/ | ||
|
@@ -172,6 +182,34 @@ class DatafileProjectConfig implements ProjectConfigInterface | |
*/ | ||
private $_rollouts; | ||
|
||
/** | ||
* list of Attributes that will be parsed from the datafile | ||
* | ||
* @var [Attribute] | ||
*/ | ||
private $attributes; | ||
|
||
/** | ||
* list of Audiences that will be parsed from the datafile | ||
* | ||
* @var [Audience] | ||
*/ | ||
private $audiences; | ||
|
||
/** | ||
* list of Events that will be parsed from the datafile | ||
* | ||
* @var [Event] | ||
*/ | ||
private $events; | ||
|
||
/** | ||
* list of Typed Audiences that will be parsed from the datafile | ||
* | ||
* @var [typed_audience] | ||
*/ | ||
private $typedAudiences; | ||
|
||
/** | ||
* internal mapping of feature keys to feature flag models. | ||
* | ||
|
@@ -222,6 +260,8 @@ public function __construct($datafile, $logger, $errorHandler) | |
$this->_logger = $logger; | ||
$this->_errorHandler = $errorHandler; | ||
$this->_version = $config['version']; | ||
$this->environmentKey = isset($config['environmentKey']) ? $config['environmentKey'] : ''; | ||
$this->sdkKey = isset($config['sdkKey']) ? $config['sdkKey'] : ''; | ||
if (!in_array($this->_version, $supportedVersions)) { | ||
throw new InvalidDatafileVersionException( | ||
"This version of the PHP SDK does not support the given datafile version: {$this->_version}." | ||
|
@@ -230,17 +270,17 @@ public function __construct($datafile, $logger, $errorHandler) | |
|
||
$this->_accountId = $config['accountId']; | ||
$this->_projectId = $config['projectId']; | ||
$this->_anonymizeIP = isset($config['anonymizeIP'])? $config['anonymizeIP'] : false; | ||
$this->_botFiltering = isset($config['botFiltering'])? $config['botFiltering'] : null; | ||
$this->attributes = isset($config['attributes']) ? $config['attributes'] : []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming rule? I see inconsistency with and without "_" prefix though they're all private There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
$this->audiences = isset($config['audiences']) ? $config['audiences'] : []; | ||
$this->events = $config['events'] ?: []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we "?:" consistently for all these props? |
||
$this->typedAudiences = isset($config['typedAudiences']) ? $config['typedAudiences'] : []; | ||
$this->_anonymizeIP = isset($config['anonymizeIP']) ? $config['anonymizeIP'] : false; | ||
$this->_botFiltering = isset($config['botFiltering']) ? $config['botFiltering'] : null; | ||
$this->_revision = $config['revision']; | ||
$this->_sendFlagDecisions = isset($config['sendFlagDecisions']) ? $config['sendFlagDecisions'] : false; | ||
|
||
$groups = $config['groups'] ?: []; | ||
$experiments = $config['experiments'] ?: []; | ||
$events = $config['events'] ?: []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't understand why these are removed from here. all three. |
||
$attributes = $config['attributes'] ?: []; | ||
$audiences = $config['audiences'] ?: []; | ||
$typedAudiences = isset($config['typedAudiences']) ? $config['typedAudiences']: []; | ||
$rollouts = isset($config['rollouts']) ? $config['rollouts'] : []; | ||
$featureFlags = isset($config['featureFlags']) ? $config['featureFlags']: []; | ||
|
||
|
@@ -258,10 +298,10 @@ public function __construct($datafile, $logger, $errorHandler) | |
|
||
$this->_groupIdMap = ConfigParser::generateMap($groups, 'id', Group::class); | ||
$this->_experimentIdMap = ConfigParser::generateMap($experiments, 'id', Experiment::class); | ||
$this->_eventKeyMap = ConfigParser::generateMap($events, 'key', Event::class); | ||
$this->_attributeKeyMap = ConfigParser::generateMap($attributes, 'key', Attribute::class); | ||
$typedAudienceIdMap = ConfigParser::generateMap($typedAudiences, 'id', Audience::class); | ||
$this->_audienceIdMap = ConfigParser::generateMap($audiences, 'id', Audience::class); | ||
$this->_eventKeyMap = ConfigParser::generateMap($this->events, 'key', Event::class); | ||
$this->_attributeKeyMap = ConfigParser::generateMap($this->attributes, 'key', Attribute::class); | ||
$typedAudienceIdMap = ConfigParser::generateMap($this->typedAudiences, 'id', Audience::class); | ||
$this->_audienceIdMap = ConfigParser::generateMap($this->audiences, 'id', Audience::class); | ||
$this->_rollouts = ConfigParser::generateMap($rollouts, null, Rollout::class); | ||
$this->_featureFlags = ConfigParser::generateMap($featureFlags, null, FeatureFlag::class); | ||
|
||
|
@@ -449,6 +489,22 @@ public function getRevision() | |
return $this->_revision; | ||
} | ||
|
||
/** | ||
* @return string Config environmentKey. | ||
*/ | ||
public function getEnvironmentKey() | ||
{ | ||
return $this->environmentKey; | ||
} | ||
|
||
/** | ||
* @return string Config sdkKey. | ||
*/ | ||
public function getSdkKey() | ||
{ | ||
return $this->sdkKey; | ||
} | ||
|
||
/** | ||
* @return array List of feature flags parsed from the datafile | ||
*/ | ||
|
@@ -457,6 +513,38 @@ public function getFeatureFlags() | |
return $this->_featureFlags; | ||
} | ||
|
||
/** | ||
* @return array List of attributes parsed from the datafile | ||
*/ | ||
public function getAttributes() | ||
{ | ||
return $this->attributes; | ||
} | ||
|
||
/** | ||
* @return array List of audiences parsed from the datafile | ||
*/ | ||
public function getAudiences() | ||
{ | ||
return $this->audiences; | ||
} | ||
|
||
/** | ||
* @return array List of events parsed from the datafile | ||
*/ | ||
public function getEvents() | ||
{ | ||
return $this->events; | ||
} | ||
|
||
/** | ||
* @return array List of typed audiences parsed from the datafile | ||
*/ | ||
public function getTypedAudiences() | ||
{ | ||
return $this->typedAudiences; | ||
} | ||
|
||
/** | ||
* @return array List of all experiments (including group experiments) | ||
* parsed from the datafile | ||
|
@@ -470,9 +558,12 @@ public function getAllExperiments() | |
$rolloutExperimentIds[] = $experiment->getId(); | ||
} | ||
} | ||
return array_filter(array_values($this->_experimentKeyMap), function ($experiment) use ($rolloutExperimentIds) { | ||
return !in_array($experiment->getId(), $rolloutExperimentIds); | ||
}); | ||
return array_filter( | ||
array_values($this->_experimentIdMap), | ||
function ($experiment) use ($rolloutExperimentIds) { | ||
return !in_array($experiment->getId(), $rolloutExperimentIds); | ||
} | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this diff needed. it looks like only indentation/formatting change? |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,37 @@ public function getBotFiltering(); | |
*/ | ||
public function getRevision(); | ||
|
||
/** | ||
* @return string String represnting environment key of the datafile. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use "representing" instead of "represnting" if you want . If you leave a comment, try to keep in mind the text. This is a minor correction, however--I wouldn't gate an entire review on it. |
||
*/ | ||
public function getEnvironmentKey(); | ||
|
||
/** | ||
* @return string String representing sdkkey of the datafile. | ||
*/ | ||
public function getSdkKey(); | ||
|
||
/** | ||
* @return array List of attributes parsed from the datafile | ||
*/ | ||
public function getAttributes(); | ||
|
||
/** | ||
* @return array List of audiences parsed from the datafile | ||
*/ | ||
public function getAudiences(); | ||
|
||
/** | ||
* @return array List of events parsed from the datafile | ||
*/ | ||
public function getEvents(); | ||
|
||
/** | ||
* @return array List of typed audiences parsed from the datafile | ||
*/ | ||
public function getTypedAudiences(); | ||
|
||
|
||
/** | ||
* @return array List of feature flags parsed from the datafile | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright 2021, Optimizely Inc and Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
namespace Optimizely\OptimizelyConfig; | ||
|
||
class OptimizelyAttribute implements \JsonSerializable | ||
{ | ||
/** | ||
* @var string id representing attribute. | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string key representing attribute. | ||
*/ | ||
private $key; | ||
|
||
public function __construct($id, $key) | ||
{ | ||
$this->id = $id; | ||
$this->key = $key; | ||
} | ||
|
||
/** | ||
* @return string attribute id. | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string attribute key. | ||
*/ | ||
public function getKey() | ||
{ | ||
return $this->key; | ||
} | ||
|
||
/** | ||
* @return string JSON representation of the object. | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return get_object_vars($this); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright 2021, Optimizely Inc and Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
namespace Optimizely\OptimizelyConfig; | ||
|
||
class OptimizelyAudience implements \JsonSerializable | ||
{ | ||
/** | ||
* @var string representing audience id. | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string representing audience name . | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var string conditions representing audience conditions. | ||
*/ | ||
private $conditions; | ||
|
||
|
||
public function __construct($id, $name, $conditions) | ||
{ | ||
$this->id = $id; | ||
$this->name = $name; | ||
$this->conditions = $conditions; | ||
} | ||
|
||
/** | ||
* @return string audience id. | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string audience name. | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return string audience conditions. | ||
*/ | ||
public function getConditions() | ||
{ | ||
return $this->conditions; | ||
} | ||
|
||
/** | ||
* @return string JSON representation of the object. | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return get_object_vars($this); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure but assuming it represents the type, should'nt it be
[AUDIENCE]
instead of[typed_audience]