コード例 #1
0
ファイル: SplitResource.php プロジェクト: splitio/php-client
 /**
  * @return bool|null
  */
 public function getSplitChanges()
 {
     //Fetching next since value from cache.
     $splitCache = new SplitCache();
     $since_cached_value = $splitCache->getChangeNumber();
     Di::getLogger()->info("SINCE CACHED VALUE: {$since_cached_value}");
     $servicePath = $this->servicePath . '?since=' . $since_cached_value;
     Di::getLogger()->info("SERVICE PATH: {$servicePath}");
     $response = $this->get($servicePath);
     if ($response->isSuccessful()) {
         $splitChanges = json_decode($response->getBody(), true);
         if (isset($splitChanges['since']) && isset($splitChanges['till']) && $splitChanges['since'] == $splitChanges['till']) {
             Di::getLogger()->info("Registering splits ready mark");
             $dateTimeUTC = new \DateTime("now", new \DateTimeZone("UTC"));
             $bur = new BlockUntilReadyCache();
             $bur->setReadySplits($dateTimeUTC->getTimestamp());
         }
         $splits = isset($splitChanges['splits']) ? $splitChanges['splits'] : false;
         if (!$splits) {
             Di::getLogger()->notice("Splits returned by the server are empty");
             return false;
         }
         return $splitChanges;
     }
     return false;
 }
コード例 #2
0
 /**
  * @depends testDiLog
  * @depends testDiCache
  */
 public function testSplitCacheInterface()
 {
     $splitChanges = file_get_contents(__DIR__ . "/../../files/splitChanges.json");
     $this->assertJson($splitChanges);
     $splitCache = new SplitCache();
     $splitChanges = json_decode($splitChanges, true);
     $splits = $splitChanges['splits'];
     $split = $splits[0];
     $splitName = $split['name'];
     $this->assertTrue($splitCache->addSplit($splitName, json_encode($split)));
     $this->assertEquals(strlen(json_encode($split)), strlen($splitCache->getSplit($splitName)));
     $this->assertTrue($splitCache->removeSplit($splitName));
     $this->assertTrue($splitCache->setChangeNumber($splitChanges['till']));
     $this->assertEquals($splitChanges['till'], $splitCache->getChangeNumber());
 }
コード例 #3
0
ファイル: SplitCommand.php プロジェクト: splitio/php-client
 public function execute()
 {
     //Fetching the Splits changes
     $splitChanges = $this->getSplitClient()->getSplitChanges();
     $splits = isset($splitChanges['splits']) ? $splitChanges['splits'] : array();
     $splitCache = new SplitCache();
     if (!empty($splits)) {
         foreach ($splits as $split) {
             if (!is_array($split) || !isset($split['name']) || !isset($split['conditions']) || !isset($split['status'])) {
                 continue;
                 //continue with next Split
             }
             $this->logger()->debug(print_r($split, true));
             $splitName = $split['name'];
             $splitStatus = $split['status'];
             $splitConditions = $split['conditions'];
             foreach ($splitConditions as $condition) {
                 foreach ($condition['matcherGroup']['matchers'] as $matcher) {
                     if ($matcher['matcherType'] == "IN_SEGMENT") {
                         //Register segment to retrieve Segment Data.
                         SegmentCache::registerSegment($matcher['userDefinedSegmentMatcherData']['segmentName']);
                     }
                 }
             }
             if ($splitStatus == 'ACTIVE') {
                 //Update Cache
                 $splitCache->addSplit($splitName, json_encode($split));
             } else {
                 //Delete item from cache
                 $splitCache->removeSplit($splitName);
             }
         }
     }
     if (isset($splitChanges['till'])) {
         $till = $splitChanges['till'];
         $this->logger()->debug("Splits Till value: {$till}");
         //Updating next since (till) value.
         if ($till != $splitCache->getChangeNumber()) {
             $splitCache->setChangeNumber($till);
         }
     }
 }