forKeys() public static method

Creates an exception for multiple keys that were not found.
public static forKeys ( array $keys, Exception $cause = null ) : static
$keys array The keys that were not found.
$cause Exception The exception that caused this exception.
return static The created exception.
 /**
  * {@inheritdoc}
  */
 public function getMultipleOrFail(array $keys)
 {
     KeyUtil::validateMultiple($keys);
     // Normalize indices of the array
     $keys = array_values($keys);
     $values = array();
     $notFoundKeys = array();
     try {
         $serializedValues = $this->clientGetMultiple($keys);
     } catch (Exception $e) {
         throw ReadException::forException($e);
     }
     foreach ($serializedValues as $i => $serializedValue) {
         if ($this->clientNotFoundValue() === $serializedValue) {
             $notFoundKeys[] = $keys[$i];
         } elseif (0 === count($notFoundKeys)) {
             $values[$keys[$i]] = Serializer::unserialize($serializedValue);
         }
     }
     if (0 !== count($notFoundKeys)) {
         throw NoSuchKeyException::forKeys($notFoundKeys);
     }
     return $values;
 }
示例#2
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;
 }
 /**
  * {@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;
 }
示例#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);
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function getMultipleOrFail(array $keys)
 {
     throw NoSuchKeyException::forKeys($keys);
 }
示例#6
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;
 }