forKey() public static method

Creates an exception for a key that was not found.
public static forKey ( string | integer $key, Exception $cause = null ) : static
$key string | integer The key that was not found.
$cause Exception The exception that caused this exception.
return static The created exception.
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getOrFail($key)
 {
     KeyUtil::validate($key);
     $dbResult = $this->getDbRow($key);
     if (null === $dbResult) {
         throw NoSuchKeyException::forKey($key);
     }
     return Serializer::unserialize($dbResult['meta_value']);
 }
 /**
  * {@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 getOrFail($key)
 {
     KeyUtil::validate($key);
     try {
         $document = $this->collection->findOne(array('_id' => $key), array('typeMap' => self::$typeMap));
     } catch (Exception $e) {
         throw ReadException::forException($e);
     }
     if (null === $document) {
         throw NoSuchKeyException::forKey($key);
     }
     return $this->unserialize->__invoke($document['value']);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function getOrFail($key)
 {
     KeyUtil::validate($key);
     if (!array_key_exists($key, $this->array)) {
         throw NoSuchKeyException::forKey($key);
     }
     return call_user_func($this->unserialize, $this->array[$key]);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function getOrFail($key)
 {
     throw NoSuchKeyException::forKey($key);
 }
 /**
  * @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 getOrFail($key)
 {
     KeyUtil::validate($key);
     try {
         $object = $this->client->bucket($this->bucketName)->getBinary($key);
         $exists = $object->exists();
     } catch (Exception $e) {
         throw ReadException::forException($e);
     }
     if (!$exists) {
         throw NoSuchKeyException::forKey($key);
     }
     return Serializer::unserialize($object->getData());
 }
 /**
  * {@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;
 }