|
27 | 27 | use Optimizely\DecisionService\FeatureDecision; |
28 | 28 | use Optimizely\Entity\Experiment; |
29 | 29 | use Optimizely\Entity\FeatureVariable; |
| 30 | +use Optimizely\Enums\DecisionInfoTypes; |
30 | 31 | use Optimizely\ErrorHandler\ErrorHandlerInterface; |
31 | 32 | use Optimizely\ErrorHandler\NoOpErrorHandler; |
32 | 33 | use Optimizely\Event\Builder\EventBuilder; |
@@ -500,24 +501,41 @@ public function isFeatureEnabled($featureFlagKey, $userId, $attributes = null) |
500 | 501 | return false; |
501 | 502 | } |
502 | 503 |
|
| 504 | + $featureEnabled = false; |
503 | 505 | $decision = $this->_decisionService->getVariationForFeature($featureFlag, $userId, $attributes); |
504 | | - if (!$decision) { |
505 | | - $this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is not enabled for user '{$userId}'."); |
506 | | - return false; |
507 | | - } |
508 | | - |
509 | | - $experiment = $decision->getExperiment(); |
510 | 506 | $variation = $decision->getVariation(); |
511 | | - |
512 | | - if ($decision->getSource() == FeatureDecision::DECISION_SOURCE_EXPERIMENT) { |
513 | | - $this->sendImpressionEvent($experiment->getKey(), $variation->getKey(), $userId, $attributes); |
514 | | - } else { |
515 | | - $this->_logger->log(Logger::INFO, "The user '{$userId}' is not being experimented on Feature Flag '{$featureFlagKey}'."); |
| 507 | + if ($variation) { |
| 508 | + $experiment = $decision->getExperiment(); |
| 509 | + $featureEnabled = $variation->getFeatureEnabled(); |
| 510 | + if ($decision->getSource() == FeatureDecision::DECISION_SOURCE_EXPERIMENT) { |
| 511 | + $experimentKey = $experiment->getKey(); |
| 512 | + $variationKey = $variation->getKey(); |
| 513 | + $this->sendImpressionEvent($experimentKey, $variationKey, $userId, $attributes); |
| 514 | + } else { |
| 515 | + $this->_logger->log(Logger::INFO, "The user '{$userId}' is not being experimented on Feature Flag '{$featureFlagKey}'."); |
| 516 | + } |
516 | 517 | } |
517 | 518 |
|
518 | | - if ($variation->getFeatureEnabled()) { |
| 519 | + $attributes = is_null($attributes) ? [] : $attributes; |
| 520 | + $this->notificationCenter->sendNotifications( |
| 521 | + NotificationType::DECISION, |
| 522 | + array( |
| 523 | + DecisionInfoTypes::FEATURE, |
| 524 | + $userId, |
| 525 | + $attributes, |
| 526 | + (object) array( |
| 527 | + 'featureKey'=>$featureFlagKey, |
| 528 | + 'featureEnabled'=> $featureEnabled, |
| 529 | + 'source'=> $decision->getSource(), |
| 530 | + 'sourceExperimentKey'=> isset($experimentKey) ? $experimentKey : null, |
| 531 | + 'sourceVariationKey'=> isset($variationKey) ? $variationKey : null |
| 532 | + ) |
| 533 | + ) |
| 534 | + ); |
| 535 | + |
| 536 | + if ($featureEnabled == true) { |
519 | 537 | $this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is enabled for user '{$userId}'."); |
520 | | - return true; |
| 538 | + return $featureEnabled; |
521 | 539 | } |
522 | 540 |
|
523 | 541 | $this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is not enabled for user '{$userId}'."); |
@@ -611,8 +629,9 @@ public function getFeatureVariableValueForType( |
611 | 629 |
|
612 | 630 | $decision = $this->_decisionService->getVariationForFeature($featureFlag, $userId, $attributes); |
613 | 631 | $variableValue = $variable->getDefaultValue(); |
| 632 | + $variation = $decision->getVariation(); |
614 | 633 |
|
615 | | - if (!$decision) { |
| 634 | + if ($variation === null) { |
616 | 635 | $this->_logger->log( |
617 | 636 | Logger::INFO, |
618 | 637 | "User '{$userId}'is not in any variation, ". |
|
0 commit comments