Skip to content

Commit

Permalink
Merge branch 'master' into fahad/readme-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aliabbasrizvi committed Aug 26, 2019
2 parents 5cdb495 + b9cdcc2 commit 53d1489
Show file tree
Hide file tree
Showing 25 changed files with 1,339 additions and 264 deletions.
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ after_script: "vendor/bin/php-coveralls -v"
stages:
- 'Linting'
- 'Integration tests'
- 'Benchmarking tests'
- 'Test'

jobs:
Expand All @@ -30,14 +31,18 @@ jobs:
script: 'composer lint'
after_script: skip
after_success: travis_terminate 0
- stage: 'Integration tests'
- &integrationtest
stage: 'Integration tests'
merge_mode: replace
env: SDK=php
env: SDK=php SDK_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH
cache: false
language: minimal
install: skip
before_script:
- mkdir $HOME/travisci-tools && pushd $HOME/travisci-tools && git init && git pull https://$CI_USER_TOKEN@github.com/optimizely/travisci-tools.git && popd
script:
- "$HOME/travisci-tools/fsc-trigger/trigger_fullstack-sdk-compat.sh"
- $HOME/travisci-tools/trigger-script-with-status-update.sh
after_success: travis_terminate 0
- <<: *integrationtest
stage: 'Benchmarking tests'
env: SDK=php FULLSTACK_TEST_REPO=Benchmarking SDK_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH
16 changes: 16 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in the repo.
# Unless a later match takes precedence, @global-owner1 and @global-owner2
# will be requested for review when someone opens a pull request.
* @optimizely/fullstack-devs

# Order is important; the last matching pattern takes the most precedence.
# When someone opens a pull request that only modifies JS files, only @js-owner
# and not the global owner(s) will be requested for a review.
#*.js @js-owner

# You can also use email addresses if you prefer. They'll be used to look up
# users just like we do for commit author emails.
#docs/* docs@example.com
5 changes: 3 additions & 2 deletions src/Optimizely/Bucketer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Optimizely;

use Monolog\Logger;
use Optimizely\Config\ProjectConfigInterface;
use Optimizely\Entity\Experiment;
use Optimizely\Entity\Variation;
use Optimizely\Logger\LoggerInterface;
Expand Down Expand Up @@ -131,14 +132,14 @@ private function findBucket($bucketingId, $userId, $parentId, $trafficAllocation
/**
* Determine variation the user should be put in.
*
* @param $config ProjectConfig Configuration for the project.
* @param $config ProjectConfigInterface Configuration for the project.
* @param $experiment Experiment Experiment in which user is to be bucketed.
* @param $bucketingId string A customer-assigned value used to create the key for the murmur hash.
* @param $userId string User identifier.
*
* @return Variation Variation which will be shown to the user.
*/
public function bucket(ProjectConfig $config, Experiment $experiment, $bucketingId, $userId)
public function bucket(ProjectConfigInterface $config, Experiment $experiment, $bucketingId, $userId)
{
if (is_null($experiment->getKey())) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016, 2018-2019 Optimizely
* Copyright 2019, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,9 @@
* limitations under the License.
*/

namespace Optimizely;
namespace Optimizely\Config;

use Exception;
use Monolog\Logger;
use Optimizely\Entity\Attribute;
use Optimizely\Entity\Audience;
Expand All @@ -37,20 +38,23 @@
use Optimizely\Exceptions\InvalidFeatureFlagException;
use Optimizely\Exceptions\InvalidFeatureVariableException;
use Optimizely\Exceptions\InvalidGroupException;
use Optimizely\Exceptions\InvalidInputException;
use Optimizely\Exceptions\InvalidRolloutException;
use Optimizely\Exceptions\InvalidVariationException;
use Optimizely\Logger\LoggerInterface;
use Optimizely\Logger\DefaultLogger;
use Optimizely\Optimizely;
use Optimizely\Utils\ConditionDecoder;
use Optimizely\Utils\ConfigParser;
use Optimizely\Utils\Errors;
use Optimizely\Utils\Validator;

/**
* Class ProjectConfig
* Class DatafileProjectConfig
*
* @package Optimizely
*/
class ProjectConfig
class DatafileProjectConfig implements ProjectConfigInterface
{
const RESERVED_ATTRIBUTE_PREFIX = '$opt_';
const V2 = '2';
Expand Down Expand Up @@ -182,7 +186,7 @@ class ProjectConfig
private $_experimentFeatureMap;

/**
* ProjectConfig constructor to load and set project configuration data.
* DatafileProjectConfig constructor to load and set project configuration data.
*
* @param $datafile string JSON string representing the project.
* @param $logger LoggerInterface
Expand Down Expand Up @@ -304,6 +308,41 @@ public function __construct($datafile, $logger, $errorHandler)
}
}

/**
* Create ProjectConfig based on datafile string.
*
* @param string $datafile JSON string representing the Optimizely project.
* @param bool $skipJsonValidation boolean representing whether JSON schema validation needs to be performed.
* @param LoggerInterface $logger Logger instance
* @param ErrorHandlerInterface $errorHandler ErrorHandler instance.
* @return ProjectConfig ProjectConfig instance or null;
*/
public static function createProjectConfigFromDatafile($datafile, $skipJsonValidation, $logger, $errorHandler)
{
if (!$skipJsonValidation) {
if (!Validator::validateJsonSchema($datafile)) {
$defaultLogger = new DefaultLogger();
$defaultLogger->log(Logger::ERROR, 'Provided "datafile" has invalid schema.');
$logger->log(Logger::ERROR, 'Provided "datafile" has invalid schema.');
return null;
}
}

try {
$config = new DatafileProjectConfig($datafile, $logger, $errorHandler);
} catch (Exception $exception) {
$defaultLogger = new DefaultLogger();
$errorMsg = $exception->getCode() == InvalidDatafileVersionException::class ? $exception->getMessage() : sprintf(Errors::INVALID_FORMAT, 'datafile');
$errorToHandle = $exception->getCode() == InvalidDatafileVersionException::class ? new InvalidDatafileVersionException($errorMsg) : new InvalidInputException($errorMsg);
$defaultLogger->log(Logger::ERROR, $errorMsg);
$logger->log(Logger::ERROR, $errorMsg);
$errorHandler->handleError($errorToHandle);
return null;
}

return $config;
}

/**
* @return string String representing account ID from the datafile.
*/
Expand Down Expand Up @@ -500,7 +539,7 @@ public function getAttribute($attributeKey)

$this->_logger->log(Logger::ERROR, sprintf('Attribute key "%s" is not in datafile.', $attributeKey));
$this->_errorHandler->handleError(new InvalidAttributeException('Provided attribute is not in datafile.'));

return null;
}

Expand Down Expand Up @@ -593,12 +632,6 @@ public function getFeatureVariableFromKey($featureFlagKey, $variableKey)
return null;
}

public function isVariationIdValid($experimentKey, $variationId)
{
return isset($this->_variationIdMap[$experimentKey]) &&
isset($this->_variationIdMap[$experimentKey][$variationId]);
}

/**
* Determines if given experiment is a feature test.
*
Expand Down
157 changes: 157 additions & 0 deletions src/Optimizely/Config/ProjectConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php
/**
* Copyright 2016, 2018-2019 Optimizely
*
* 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\Config;

/**
* Interface ProjectConfigInterface
*
* @package Optimizely
*/
interface ProjectConfigInterface
{
/**
* @return string String representing account ID from the datafile.
*/
public function getAccountId();

/**
* @return string String representing project ID from the datafile.
*/
public function getProjectId();

/**
* @return boolean Flag denoting if Optimizely should remove last block
* of visitors' IP address before storing event data
*/
public function getAnonymizeIP();

/**
* @return boolean Flag denoting if Optimizely should perform
* bot filtering on your dispatched events.
*/
public function getBotFiltering();

/**
* @return string String representing revision of the datafile.
*/
public function getRevision();

/**
* @return array List of feature flags parsed from the datafile
*/
public function getFeatureFlags();

/**
* @param $groupId string ID of the group.
*
* @return Group Entity corresponding to the ID.
* Dummy entity is returned if ID is invalid.
*/
public function getGroup($groupId);

/**
* @param $experimentKey string Key of the experiment.
*
* @return Experiment Entity corresponding to the key.
* Dummy entity is returned if key is invalid.
*/
public function getExperimentFromKey($experimentKey);

/**
* @param $experimentId string ID of the experiment.
*
* @return Experiment Entity corresponding to the key.
* Dummy entity is returned if ID is invalid.
*/
public function getExperimentFromId($experimentId);

/**
* @param String $featureKey Key of the feature flag
*
* @return FeatureFlag Entity corresponding to the key.
*/
public function getFeatureFlagFromKey($featureKey);

/**
* @param String $rolloutId
*
* @return Rollout
*/
public function getRolloutFromId($rolloutId);

/**
* @param $eventKey string Key of the event.
*
* @return Event Entity corresponding to the key.
* Dummy entity is returned if key is invalid.
*/
public function getEvent($eventKey);

/**
* @param $audienceId string ID of the audience.
*
* @return Audience Entity corresponding to the ID.
* Null is returned if ID is invalid.
*/
public function getAudience($audienceId);

/**
* @param $attributeKey string Key of the attribute.
*
* @return Attribute Entity corresponding to the key.
* Null is returned if key is invalid.
*/
public function getAttribute($attributeKey);

/**
* @param $experimentKey string Key for experiment.
* @param $variationKey string Key for variation.
*
* @return Variation Entity corresponding to the provided experiment key and variation key.
* Dummy entity is returned if key or ID is invalid.
*/
public function getVariationFromKey($experimentKey, $variationKey);

/**
* @param $experimentKey string Key for experiment.
* @param $variationId string ID for variation.
*
* @return Variation Entity corresponding to the provided experiment key and variation ID.
* Dummy entity is returned if key or ID is invalid.
*/
public function getVariationFromId($experimentKey, $variationId);

/**
* Gets the feature variable instance given feature flag key and variable key
*
* @param string Feature flag key
* @param string Variable key
*
* @return FeatureVariable / null
*/
public function getFeatureVariableFromKey($featureFlagKey, $variableKey);

/**
* Determines if given experiment is a feature test.
*
* @param string Experiment ID.
*
* @return boolean A boolean value that indicates if the experiment is a feature test.
*/
public function isFeatureExperiment($experimentId);
}

0 comments on commit 53d1489

Please sign in to comment.