コード例 #1
0
 public function testFromArray()
 {
     $array = array('key' => 'key', 'value' => 'value', 'ttl' => 1);
     $item = ItemTransformer::fromArray($array);
     $this->assertEquals('key', $item->getKey());
     $this->assertEquals('value', $item->getValue());
     $this->assertEquals(1, $item->getTtl());
 }
コード例 #2
0
 /**
  * @param array $keys
  * @return MCacheItem[]
  */
 public function getItems(array $keys)
 {
     $array = array();
     foreach ($keys as $key) {
         $now = new \DateTime();
         $path = $this->getBackupFilePath($key);
         if (file_exists($path)) {
             $json = file_get_contents($path);
             $array = json_decode($json, true);
             $item = ItemTransformer::fromArray($array);
             $endValidation = \DateTime::createFromFormat(self::FILE_DATE_FORMAT, $array['end_validation']);
             if ($endValidation >= $now) {
                 $array[] = $item;
             }
         }
     }
     return $array;
 }