Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Inheritance: extends RuntimeExceptio\RuntimeException
 /**
  * {@inheritdoc}
  */
 public function getOrFail($key)
 {
     KeyUtil::validate($key);
     try {
         $serialized = $this->clientGet($key);
     } catch (Exception $e) {
         throw ReadException::forException($e);
     }
     if ($this->clientNotFoundValue() === $serialized) {
         throw NoSuchKeyException::forKey($key);
     }
     return Serializer::unserialize($serialized);
 }
 /**
  * {@inheritdoc}
  */
 public function getMultipleOrFail(array $keys)
 {
     KeyUtil::validateMultiple($keys);
     $values = array();
     try {
         $cursor = $this->collection->find(array('_id' => array('$in' => array_values($keys))), array('typeMap' => self::$typeMap));
         foreach ($cursor as $document) {
             $values[$document['_id']] = $this->unserialize->__invoke($document['value']);
         }
     } catch (UnserializationFailedException $e) {
         throw $e;
     } catch (Exception $e) {
         throw ReadException::forException($e);
     }
     $notFoundKeys = array_diff($keys, array_keys($values));
     if (count($notFoundKeys) > 0) {
         throw NoSuchKeyException::forKeys($notFoundKeys);
     }
     return $values;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getMultipleOrFail(array $keys)
 {
     KeyUtil::validateMultiple($keys);
     // Normalize indices of the array
     $keys = array_values($keys);
     $data = $this->doGetMultiple($keys);
     $results = array();
     $resolved = array();
     foreach ($data as $row) {
         $results[$row['meta_key']] = Serializer::unserialize($row['meta_value']);
         $resolved[] = $row['meta_key'];
     }
     $notResolvedArr = array_diff($keys, $resolved);
     if (!empty($notResolvedArr)) {
         throw NoSuchKeyException::forKeys($notResolvedArr);
     }
     return $results;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function getMultipleOrFail(array $keys)
 {
     KeyUtil::validateMultiple($keys);
     $notFoundKeys = array_diff($keys, array_keys($this->array));
     if (count($notFoundKeys) > 0) {
         throw NoSuchKeyException::forKeys($notFoundKeys);
     }
     return $this->getMultiple($keys);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function getMultipleOrFail(array $keys)
 {
     throw NoSuchKeyException::forKeys($keys);
 }
 /**
  * @expectedException \Webmozart\KeyValueStore\Api\NoSuchKeyException
  */
 public function testGetOrFailForwardsNoSuchKeyException()
 {
     $this->cache->expects($this->once())->method('contains')->with('key')->willReturn(false);
     $this->innerStore->expects($this->once())->method('getOrFail')->willThrowException(NoSuchKeyException::forKey('key'));
     $this->cache->expects($this->never())->method('save');
     $this->decorator->getOrFail('key');
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function getMultipleOrFail(array $keys)
 {
     KeyUtil::validateMultiple($keys);
     $values = array();
     $notFoundKeys = array();
     try {
         $bucket = $this->client->bucket($this->bucketName);
         foreach ($keys as $key) {
             $values[$key] = $bucket->getBinary($key);
             if (!$values[$key]->exists()) {
                 $notFoundKeys[] = $key;
             }
         }
     } catch (Exception $e) {
         throw ReadException::forException($e);
     }
     if (0 !== count($notFoundKeys)) {
         throw NoSuchKeyException::forKeys($notFoundKeys);
     }
     foreach ($values as $key => $object) {
         $values[$key] = Serializer::unserialize($object->getData());
     }
     return $values;
 }
 /**
  * {@inheritdoc}
  */
 public function getMultipleOrFail(array $keys)
 {
     $values = array();
     $data = $this->load();
     foreach ($keys as $key) {
         KeyUtil::validate($key);
         if (!array_key_exists($key, $data)) {
             throw NoSuchKeyException::forKey($key);
         }
         $values[$key] = $this->unserializeValue($data[$key]);
     }
     return $values;
 }