-
Notifications
You must be signed in to change notification settings - Fork 0
Config v2 branch #1
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
005fce8
0b98993
cb17173
08c9280
b6aa75d
d018352
4ca2344
196440f
d547071
14d1380
c8625e6
61d5864
e142a24
5cfdf6c
022e175
421fc2c
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 | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||
<?php | ||||||
/** | ||||||
* Copyright 2019-2020, Optimizely | ||||||
* Copyright 2019-2021, Optimizely | ||||||
* | ||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
* you may not use this file except in compliance with the License. | ||||||
|
@@ -93,6 +93,18 @@ 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. | ||||||
*/ | ||||||
|
@@ -162,6 +174,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 [Audiences] | ||||||
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.
Suggested change
|
||||||
*/ | ||||||
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. | ||||||
* | ||||||
|
@@ -212,6 +252,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}." | ||||||
|
@@ -220,17 +262,17 @@ public function __construct($datafile, $logger, $errorHandler) | |||||
|
||||||
$this->_accountId = $config['accountId']; | ||||||
$this->_projectId = $config['projectId']; | ||||||
$this->attributes = $config['attributes'] ?: []; | ||||||
$this->audiences = $config['audiences'] ?: []; | ||||||
$this->events = $config['events'] ?: []; | ||||||
$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. any reason to remove it? 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. they were being used as variables but i need to get them as attributes so delete the variables and using attributes in further functions |
||||||
$attributes = $config['attributes'] ?: []; | ||||||
$audiences = $config['audiences'] ?: []; | ||||||
$typedAudiences = isset($config['typedAudiences']) ? $config['typedAudiences']: []; | ||||||
$rollouts = isset($config['rollouts']) ? $config['rollouts'] : []; | ||||||
$featureFlags = isset($config['featureFlags']) ? $config['featureFlags']: []; | ||||||
|
||||||
|
@@ -248,10 +290,10 @@ public function __construct($datafile, $logger, $errorHandler) | |||||
|
||||||
$this->_groupIdMap = ConfigParser::generateMap($groups, 'id', Group::class); | ||||||
$this->_experimentKeyMap = ConfigParser::generateMap($experiments, 'key', 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); | ||||||
|
||||||
|
@@ -425,6 +467,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 | ||||||
*/ | ||||||
|
@@ -433,6 +491,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 | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||
<?php | ||||||
/** | ||||||
* Copyright 2016, 2018-2020 Optimizely | ||||||
* Copyright 2016, 2018-2021 Optimizely | ||||||
* | ||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
* you may not use this file except in compliance with the License. | ||||||
|
@@ -51,6 +51,37 @@ public function getBotFiltering(); | |||||
*/ | ||||||
public function getRevision(); | ||||||
|
||||||
/** | ||||||
* @return string String represnting envkey 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.
Suggested change
|
||||||
*/ | ||||||
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(); | ||||||
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. following are not a part of ProjectConfigInterface 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. attributes, audiences, events, typedAudiences. |
||||||
|
||||||
/** | ||||||
* @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 id representing audience. | ||||||
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.
Suggested change
|
||||||
*/ | ||||||
private $id; | ||||||
|
||||||
/** | ||||||
* @var string name representing audience. | ||||||
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.
Suggested change
|
||||||
*/ | ||||||
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.
update header of this file and all others. 2021