Skip to content

Commit

Permalink
Merge 563003b into f15e5f7
Browse files Browse the repository at this point in the history
  • Loading branch information
ozayr-zaviar committed Aug 24, 2021
2 parents f15e5f7 + 563003b commit b21fab8
Show file tree
Hide file tree
Showing 12 changed files with 1,315 additions and 117 deletions.
110 changes: 99 additions & 11 deletions src/Optimizely/Config/DatafileProjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 [Audience]
*/
private $typedAudiences;

/**
* internal mapping of feature keys to feature flag models.
*
Expand Down Expand Up @@ -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}."
Expand All @@ -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->_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'] ?: [];
$attributes = $config['attributes'] ?: [];
$audiences = $config['audiences'] ?: [];
$typedAudiences = isset($config['typedAudiences']) ? $config['typedAudiences']: [];
$this->attributes = isset($config['attributes']) ? $config['attributes'] : [];
$this->audiences = isset($config['audiences']) ? $config['audiences'] : [];
$this->events = isset($config['events']) ? $config['events'] : [];
$this->typedAudiences = isset($config['typedAudiences']) ? $config['typedAudiences'] : [];
$rollouts = isset($config['rollouts']) ? $config['rollouts'] : [];
$featureFlags = isset($config['featureFlags']) ? $config['featureFlags']: [];

Expand All @@ -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);

Expand Down Expand Up @@ -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
*/
Expand All @@ -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
Expand All @@ -470,7 +558,7 @@ public function getAllExperiments()
$rolloutExperimentIds[] = $experiment->getId();
}
}
return array_filter(array_values($this->_experimentKeyMap), function ($experiment) use ($rolloutExperimentIds) {
return array_filter(array_values($this->_experimentIdMap), function ($experiment) use ($rolloutExperimentIds) {
return !in_array($experiment->getId(), $rolloutExperimentIds);
});
}
Expand Down
31 changes: 31 additions & 0 deletions src/Optimizely/Config/ProjectConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ public function getBotFiltering();
*/
public function getRevision();

/**
* @return string String representing environment key of the datafile.
*/
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
*/
Expand Down
60 changes: 60 additions & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyAttribute.php
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);
}
}
75 changes: 75 additions & 0 deletions src/Optimizely/OptimizelyConfig/OptimizelyAudience.php
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);
}
}

0 comments on commit b21fab8

Please sign in to comment.