public function __construct(array $partition) { SplitApp::logger()->debug(print_r($partition, true)); if (isset($partition['treatment']) && !empty($partition['treatment'])) { $this->setTreatment($partition['treatment']); } $size = isset($partition['size']) && is_int($partition['size']) && $partition['size'] >= 0 && $partition['size'] <= 100 ? $partition['size'] : 0; $this->setSize($size); }
/** * @param $splitCacheKey * @return null|SplitView */ private function getSplitByCacheKey($splitCacheKey) { $splitCachedItem = SplitApp::cache()->getItem($splitCacheKey); if ($splitCachedItem->isHit()) { $splitRepresentation = $splitCachedItem->get(); $split = new Split(json_decode($splitRepresentation, true)); return new SplitView($split->getName(), $split->getTrafficTypeName(), $split->killed(), $split->getTreatments(), $split->getChangeNumber()); } return null; }
/** * @param string $key * @param long $seed * @param array $partitions * @return null|string */ public static function getTreatment($key, $seed, $partitions) { $logMsg = "Splitter evaluating partitions ... \n\n Bucketing Key: {$key} \n\n Seed: {$seed} \n\n Partitions: " . print_r($partitions, true); SplitApp::logger()->debug($logMsg); $bucket = abs(\SplitIO\hash($key, $seed) % 100) + 1; SplitApp::logger()->info("Butcket: " . $bucket); $accumulatedSize = 0; foreach ($partitions as $partition) { if ($partition instanceof Partition) { $accumulatedSize += $partition->getSize(); if ($bucket <= $accumulatedSize) { return $partition->getTreatment(); } } } return null; }
public function __construct(array $split) { SplitApp::logger()->debug(print_r($split, true)); $this->name = $split['name']; $this->trafficTypeName = $split['trafficTypeName']; $this->seed = $split['seed']; $this->status = $split['status']; $this->killed = $split['killed']; $this->defaultTreatment = $split['defaultTreatment']; $this->changeNumber = isset($split['changeNumber']) ? $split['changeNumber'] : -1; SplitApp::logger()->info("Constructing Split: " . $this->name); if (isset($split['conditions']) && is_array($split['conditions'])) { $this->conditions = array(); foreach ($split['conditions'] as $condition) { $this->conditions[] = new Condition($condition); } } }
/** * @param array $condition */ public function __construct(array $condition) { SplitApp::logger()->debug(print_r($condition, true)); SplitApp::logger()->info("Constructing Condition"); //So far the combiner is AND. On next versions the condition will support Combiners: OR $this->combiner = new CombinerEnum(CombinerEnum::_AND); if (isset($condition['partitions']) && is_array($condition['partitions'])) { $this->partitions = array(); foreach ($condition['partitions'] as $partition) { $this->partitions[] = new Partition($partition); } } if (isset($condition['matcherGroup']['matchers']) && is_array($condition['matcherGroup']['matchers'])) { $this->matcherGroup = array(); foreach ($condition['matcherGroup']['matchers'] as $matcher) { $this->matcherGroup[] = Matcher::factory($matcher); } } }
/** * @param $key * @return bool */ protected function evalKey($key) { if (!is_long($key)) { return false; } SplitApp::logger()->info('---> Evaluating LESS_THAN_OR_EQUAL_TO'); if (isset($this->unaryNumericMatcherData['value'])) { $logMsg = '---> KEY: ' . $key; $logMsg .= PHP_EOL . '---> VAL: ' . $this->unaryNumericMatcherData['value']; $logMsg .= PHP_EOL . '---> ATR: ' . $this->attribute; SplitApp::logger()->info($logMsg); if (isset($this->unaryNumericMatcherData['dataType']) && DataTypeEnum::isValid($this->unaryNumericMatcherData['dataType'])) { if (DataTypeEnum::DATETIME == $this->unaryNumericMatcherData['dataType']) { $phpTimestamp = DateTime::millisecondToPHPTimestamp($this->unaryNumericMatcherData['value']); return DateTime::zeroOutSeconds($key) <= DateTime::zeroOutSeconds($phpTimestamp); } } return $key <= $this->unaryNumericMatcherData['value']; } return false; }
/** * @param $key * @return bool */ protected function evalKey($key) { if (!is_long($key)) { return false; } SplitApp::logger()->info('---> Evaluating BETWEEN'); if (isset($this->betweenMatcherData['start']) && isset($this->betweenMatcherData['end'])) { $logMsg = '---> KEY: ' . $key; $logMsg .= PHP_EOL . '---> START: ' . $this->betweenMatcherData['start']; $logMsg .= PHP_EOL . '---> END: ' . $this->betweenMatcherData['end']; $logMsg .= PHP_EOL . '---> ATR: ' . $this->attribute; SplitApp::logger()->info($logMsg); if (isset($this->betweenMatcherData['dataType']) && DataTypeEnum::isValid($this->betweenMatcherData['dataType'])) { if (DataTypeEnum::DATETIME == $this->betweenMatcherData['dataType']) { $phpTimestampStart = DateTime::millisecondToPHPTimestamp($this->betweenMatcherData['start']); $phpTimestampEnd = DateTime::millisecondToPHPTimestamp($this->betweenMatcherData['end']); $normalizedKey = DateTime::zeroOutSeconds($key); return DateTime::zeroOutSeconds($phpTimestampStart) <= $normalizedKey && $normalizedKey <= DateTime::zeroOutSeconds($phpTimestampEnd); } } return $this->betweenMatcherData['start'] <= $key && $key <= $this->betweenMatcherData['end']; } return false; }
/** * A short-hand for * <pre> * (getTreatment(key, feature) == treatment) ? true : false; * </pre> * * This method never throws exceptions. * Instead of throwing exceptions, it returns false. * * @param $key * @param $featureName * @param $treatment * @return bool */ public function isTreatment($key, $featureName, $treatment) { try { $calculatedTreatment = $this->getTreatment($key, $featureName); if ($calculatedTreatment !== TreatmentEnum::CONTROL) { if ($treatment == $calculatedTreatment) { return true; } } } catch (\Exception $e) { // @codeCoverageIgnoreStart SplitApp::logger()->critical("SDK Client on isTreatment is critical"); SplitApp::logger()->critical($e->getMessage()); SplitApp::logger()->critical($e->getTraceAsString()); // @codeCoverageIgnoreEnd } return false; }
/** * @param $segmentName * @param $key * @param $value * @return bool */ private function cacheSegmentEvaluation($segmentName, $key, $value) { $ikey = $this->getSmKey($segmentName, $key); try { return SharedMemory::write($ikey, $value, $this->smTtl, $this->smMode, $this->smSize); } catch (SupportSharedMemoryException $se) { SplitApp::logger()->warning($se->getMessage()); } catch (OpenSharedMemoryException $oe) { SplitApp::logger()->error($oe->getMessage()); } catch (WriteSharedMemoryException $we) { SplitApp::logger()->error($we->getMessage()); } catch (\Exception $e) { SplitApp::logger()->error($e->getMessage()); } return false; }
/** * @param \SplitIO\Sdk\Impressions\Impression $impression * @return bool */ public static function log(Impression $impression) { Split::logger()->debug($impression); $impressionCache = new ImpressionCache(); return $impressionCache->addDataToFeature($impression->getFeature(), $impression->getId(), $impression->getTreatment(), $impression->getTime()); }
protected function evalKey($key) { SplitApp::logger()->info("Comparing: ALL_KEYS - {$key}"); SplitApp::logger()->info("User found: {$key}"); return true; }
public function evaluate($key) { SplitApp::logger()->info("Evaluating on {$this->type} the KEY {$key}"); return $this->evalKey($key); }