public function isFeatureEnabled($featureFlagKey, $userId, $attributes = null)
    {
        if (!$this->_isValid) {
            $this->_logger->log(Logger::ERROR, "Datafile has invalid format. Failing '".__FUNCTION__."'.");
            return false;
        }

        if (!$this->validateInputs(
            [
                self::FEATURE_FLAG_KEY =>$featureFlagKey,
                self::USER_ID => $userId
            ]
        )
        ) {
            return false;
        }

        $featureFlag = $this->_config->getFeatureFlagFromKey($featureFlagKey);
        if ($featureFlag && (!$featureFlag->getId())) {
            // Error logged in ProjectConfig - getFeatureFlagFromKey
            return false;
        }

        //validate feature flag
        if (!Validator::isFeatureFlagValid($this->_config, $featureFlag)) {
            return false;
        }

        $featureEnabled = false;
        $decision = $this->_decisionService->getVariationForFeature($featureFlag, $userId, $attributes);
        $variation = $decision->getVariation();
        if ($variation) {
            $experiment = $decision->getExperiment();
            $featureEnabled = $variation->getFeatureEnabled();
            if ($decision->getSource() == FeatureDecision::DECISION_SOURCE_FEATURE_TEST) {
                $experimentKey = $experiment->getKey();
                $variationKey = $variation->getKey();
                $sourceInfo = (object) array(
                    'experimentKey'=> $experimentKey,
                    'variationKey'=> $variationKey
                );

                $this->sendImpressionEvent($experimentKey, $variationKey, $userId, $attributes);
            } else {
                $this->_logger->log(Logger::INFO, "The user '{$userId}' is not being experimented on Feature Flag '{$featureFlagKey}'.");
            }
        }

        $attributes = is_null($attributes) ? [] : $attributes;
        $this->notificationCenter->sendNotifications(
            NotificationType::DECISION,
            array(
                DecisionNotificationTypes::FEATURE,
                $userId,
                $attributes,
                (object) array(
                    'featureKey'=>$featureFlagKey,
                    'featureEnabled'=> $featureEnabled,
                    'source'=> $decision->getSource(),
                    'sourceInfo'=> isset($sourceInfo) ? $sourceInfo : (object) array()
                )
            )
        );

        if ($featureEnabled == true) {
            $this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is enabled for user '{$userId}'.");
            return $featureEnabled;
        }

        $this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is not enabled for user '{$userId}'.");
        return false;
    }
public function isFeatureEnabled($featureFlagKey, $userId, $attributes = null)
    {
        if (!$this->_isValid) {
            $this->_logger->log(Logger::ERROR, "Datafile has invalid format. Failing '".__FUNCTION__."'.");
            return false;
        }

        if (!$this->validateInputs(
            [
                self::FEATURE_FLAG_KEY =>$featureFlagKey,
                self::USER_ID => $userId
            ]
        )
        ) {
            return false;
        }

        $featureFlag = $this->_config->getFeatureFlagFromKey($featureFlagKey);
        if ($featureFlag && (!$featureFlag->getId())) {
            // Error logged in ProjectConfig - getFeatureFlagFromKey
            return false;
        }

        //validate feature flag
        if (!Validator::isFeatureFlagValid($this->_config, $featureFlag)) {
            return false;
        }

        $featureEnabled = false;
        $decision = $this->_decisionService->getVariationForFeature($featureFlag, $userId, $attributes);
        $variation = $decision->getVariation();
        if ($variation) {
            $experiment = $decision->getExperiment();
            $featureEnabled = $variation->getFeatureEnabled();
            if ($decision->getSource() == FeatureDecision::DECISION_SOURCE_FEATURE_TEST) {
                $experimentKey = $experiment->getKey();
                $variationKey = $variation->getKey();
                $sourceInfo = (object) array(
                    'experimentKey'=> $experimentKey,
                    'variationKey'=> $variationKey
                );

                $this->sendImpressionEvent($experimentKey, $variationKey, $userId, $attributes);
            } else {
                $this->_logger->log(Logger::INFO, "The user '{$userId}' is not being experimented on Feature Flag '{$featureFlagKey}'.");
            }
        }

        $attributes = is_null($attributes) ? [] : $attributes;
        $this->notificationCenter->sendNotifications(
            NotificationType::DECISION,
            array(
                DecisionNotificationTypes::FEATURE,
                $userId,
                $attributes,
                (object) array(
                    'featureKey'=>$featureFlagKey,
                    'featureEnabled'=> $featureEnabled,
                    'source'=> $decision->getSource(),
                    'sourceInfo'=> isset($sourceInfo) ? $sourceInfo : (object) array()
                )
            )
        );

        if ($featureEnabled == true) {
            $this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is enabled for user '{$userId}'.");
            return $featureEnabled;
        }

        $this->_logger->log(Logger::INFO, "Feature Flag '{$featureFlagKey}' is not enabled for user '{$userId}'.");
        return false;
    }
public function isFeatureEnabled ( $ featureFlagKey , $ userId , $ attributes = null ) { if ( ! $ this -> _isValid ) { $ this -> _logger -> log ( Logger :: ERROR , "Datafile has invalid format. Failing '" . __FUNCTION__ . "'." ) ; return false ; } if ( ! $ this -> validateInputs ( [ self :: FEATURE_FLAG_KEY => $ featureFlagKey , self :: USER_ID => $ userId ] ) ) { return false ; } $ featureFlag = $ this -> _config -> getFeatureFlagFromKey ( $ featureFlagKey ) ; if ( $ featureFlag && ( ! $ featureFlag -> getId ( ) ) ) { // Error logged in ProjectConfig - getFeatureFlagFromKey return false ; } //validate feature flag if ( ! Validator :: isFeatureFlagValid ( $ this -> _config , $ featureFlag ) ) { return false ; } $ featureEnabled = false ; $ decision = $ this -> _decisionService -> getVariationForFeature ( $ featureFlag , $ userId , $ attributes ) ; $ variation = $ decision -> getVariation ( ) ; if ( $ variation ) { $ experiment = $ decision -> getExperiment ( ) ; $ featureEnabled = $ variation -> getFeatureEnabled ( ) ; if ( $ decision -> getSource ( ) == FeatureDecision :: DECISION_SOURCE_FEATURE_TEST ) { $ experimentKey = $ experiment -> getKey ( ) ; $ variationKey = $ variation -> getKey ( ) ; $ sourceInfo = ( object ) array ( 'experimentKey' => $ experimentKey , 'variationKey' => $ variationKey ) ; $ this -> sendImpressionEvent ( $ experimentKey , $ variationKey , $ userId , $ attributes ) ; } else { $ this -> _logger -> log ( Logger :: INFO , "The user '{$userId}' is not being experimented on Feature Flag '{$featureFlagKey}'." ) ; } } $ attributes = is_null ( $ attributes ) ? [ ] : $ attributes ; $ this -> notificationCenter -> sendNotifications ( NotificationType :: DECISION , array ( DecisionNotificationTypes :: FEATURE , $ userId , $ attributes , ( object ) array ( 'featureKey' => $ featureFlagKey , 'featureEnabled' => $ featureEnabled , 'source' => $ decision -> getSource ( ) , 'sourceInfo' => isset ( $ sourceInfo ) ? $ sourceInfo : ( object ) array ( ) ) ) ) ; if ( $ featureEnabled == true ) { $ this -> _logger -> log ( Logger :: INFO , "Feature Flag '{$featureFlagKey}' is enabled for user '{$userId}'." ) ; return $ featureEnabled ; } $ this -> _logger -> log ( Logger :: INFO , "Feature Flag '{$featureFlagKey}' is not enabled for user '{$userId}'." ) ; return false ; }
Determine whether a feature is enabled.
Sends an impression event if the user is bucketed into an experiment using the feature.

@param string Feature flag key
@param string User ID
@param array Associative array of user attributes

@return boolean
Determine whether a feature is enabled . Sends an impression event if the user is bucketed into an experiment using the feature .