You are here

public function DatabaseStorageExpirable::getMultiple in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::getMultiple()
  2. 9 core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php \Drupal\Core\KeyValueStore\DatabaseStorageExpirable::getMultiple()

File

core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php, line 52

Class

DatabaseStorageExpirable
Defines a default key/value store implementation for expiring items.

Namespace

Drupal\Core\KeyValueStore

Code

public function getMultiple(array $keys) {
  try {
    $values = $this->connection
      ->query('SELECT [name], [value] FROM {' . $this->connection
      ->escapeTable($this->table) . '} WHERE [expire] > :now AND [name] IN ( :keys[] ) AND [collection] = :collection', [
      ':now' => REQUEST_TIME,
      ':keys[]' => $keys,
      ':collection' => $this->collection,
    ])
      ->fetchAllKeyed();
    return array_map([
      $this->serializer,
      'decode',
    ], $values);
  } catch (\Exception $e) {

    // @todo: Perhaps if the database is never going to be available,
    // key/value requests should return FALSE in order to allow exception
    // handling to occur but for now, keep it an array, always.
    // https://www.drupal.org/node/2787737
    $this
      ->catchException($e);
  }
  return [];
}