Skip to content

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 99 additions & 9 deletions src/Optimizely/Config/DatafileProjectConfig.php
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.
Expand Down Expand Up @@ -93,6 +93,18 @@ class DatafileProjectConfig implements ProjectConfigInterface
*/
private $datafile;

/**
Copy link

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

* @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 @@ -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]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var [Audiences]
* @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.
*
Expand Down Expand Up @@ -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}."
Expand All @@ -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'] ?: [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to remove it?

Copy link
Owner Author

Choose a reason for hiding this comment

The 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']: [];

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

Expand Down Expand Up @@ -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
*/
Expand All @@ -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
Expand Down
33 changes: 32 additions & 1 deletion src/Optimizely/Config/ProjectConfigInterface.php
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.
Expand Down Expand Up @@ -51,6 +51,37 @@ public function getBotFiltering();
*/
public function getRevision();

/**
* @return string String represnting envkey of the datafile.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return string String represnting envkey of the datafile.
* @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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following are not a part of ProjectConfigInterface

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attributes, audiences, events, typedAudiences.
check in other sdks, how retrieving arrays.


/**
* @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 id representing audience.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var string id representing audience.
* @var string representing audience id.

*/
private $id;

/**
* @var string name representing audience.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var string name representing audience.
* @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);
}
}
Loading