diff --git a/src/Optimizely/DecisionService/DecisionService.php b/src/Optimizely/DecisionService/DecisionService.php index c8c8a3e0..34f86db6 100644 --- a/src/Optimizely/DecisionService/DecisionService.php +++ b/src/Optimizely/DecisionService/DecisionService.php @@ -1,6 +1,6 @@ getFlagKey(); + $ruleKey = $context->getRuleKey(); + $variationKey = $user->findForcedDecision($context); + $variation = null; + if ($variationKey && $projectConfig) { + $variation = $projectConfig->getFlagVariationByKey($flagKey, $variationKey); + if ($variation) { + array_push($decideReasons, 'Decided by forced decision.'); + array_push($decideReasons, sprintf('Variation (%s) is mapped to %s and user (%s) in the forced decision map.', $variationKey, $ruleKey? 'flag ('.$flagKey.'), rule ('.$ruleKey.')': 'flag ('.$flagKey.')', $user->getUserId())); + } else { + array_push($decideReasons, sprintf('Invalid variation is mapped to %s and user (%s) in the forced decision map.', $ruleKey? 'flag ('.$flagKey.'), rule ('.$ruleKey.')': 'flag ('.$flagKey.')', $user->getUserId())); + } + } + return [$variation, $decideReasons]; + } + /** * Determine which variation to show the user. * @@ -377,7 +405,7 @@ private function getVariationFromExperimentRule(ProjectConfigInterface $projectC $decideReasons = []; // check forced-decision first $context = new OptimizelyDecisionContext($flagKey, $rule->getKey()); - list($decisionResponse, $reasons) = $user->findValidatedForcedDecision($context); + list($decisionResponse, $reasons) = $this->findValidatedForcedDecision($context, $projectConfig, $user); $decideReasons = array_merge($decideReasons, $reasons); if ($decisionResponse) { return [$decisionResponse, $decideReasons]; @@ -410,7 +438,7 @@ public function getVariationFromDeliveryRule(ProjectConfigInterface $projectConf // check forced-decision first $rule = $rules[$ruleIndex]; $context = new OptimizelyDecisionContext($flagKey, $rule->getKey()); - list($forcedDecisionResponse, $reasons) = $user->findValidatedForcedDecision($context); + list($forcedDecisionResponse, $reasons) = $this->findValidatedForcedDecision($context, $projectConfig, $user); $decideReasons = array_merge($decideReasons, $reasons); if ($forcedDecisionResponse) { diff --git a/src/Optimizely/Optimizely.php b/src/Optimizely/Optimizely.php index 179360de..4f4bc9c2 100644 --- a/src/Optimizely/Optimizely.php +++ b/src/Optimizely/Optimizely.php @@ -1,6 +1,6 @@ findValidatedForcedDecision($context); + list($forcedDecisionResponse, $reasons) = $this->_decisionService->findValidatedForcedDecision($context, $config, $userContext); if ($forcedDecisionResponse) { $decision = new FeatureDecision(null, $forcedDecisionResponse, FeatureDecision::DECISION_SOURCE_FEATURE_TEST, $decideReasons); } else { @@ -1305,17 +1305,4 @@ protected function validateInputs(array $values, $logLevel = Logger::ERROR) return $isValid; } - - /** - * Gets the variation associated with experiment or rollout in instance of given feature flag key - * - * @param string Feature flag key - * @param string variation key - * - * @return Variation / null - */ - public function getFlagVariationByKey($flagKey, $variationKey) - { - return $this->getConfig()->getFlagVariationByKey($flagKey, $variationKey); - } } diff --git a/src/Optimizely/OptimizelyUserContext.php b/src/Optimizely/OptimizelyUserContext.php index 2533b029..1e200038 100644 --- a/src/Optimizely/OptimizelyUserContext.php +++ b/src/Optimizely/OptimizelyUserContext.php @@ -1,6 +1,6 @@ getFlagKey(); - $ruleKey = $context->getRuleKey(); - $variationKey = $this->findForcedDecision($context); - $variation = null; - if ($variationKey) { - $variation = $this->optimizelyClient->getFlagVariationByKey($flagKey, $variationKey); - if ($variation) { - array_push($decideReasons, 'Decided by forced decision.'); - array_push($decideReasons, sprintf('Variation (%s) is mapped to %s and user (%s) in the forced decision map.', $variationKey, $ruleKey? 'flag ('.$flagKey.'), rule ('.$ruleKey.')': 'flag ('.$flagKey.')', $this->userId)); - } else { - array_push($decideReasons, sprintf('Invalid variation is mapped to %s and user (%s) in the forced decision map.', $ruleKey? 'flag ('.$flagKey.'), rule ('.$ruleKey.')': 'flag ('.$flagKey.')', $this->userId)); - } - } - return [$variation, $decideReasons]; - } - private function findExistingRuleAndFlagKey($context) { if ($this->forcedDecisions) {