Webmozart\KeyValueStore\Api\NoSuchKeyException::forKeys PHP Method

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.
    public static function forKeys(array $keys, Exception $cause = null)
    {
        return new static(sprintf('The keys "%s" does not exist.', implode('", "', $keys)), 0, $cause);
    }

Usage Example

 /**
  * {@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;
 }
All Usage Examples Of Webmozart\KeyValueStore\Api\NoSuchKeyException::forKeys
NoSuchKeyException