function DatabaseStorage::getMultiple

Same name in other branches
  1. 9 core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php \Drupal\Core\KeyValueStore\DatabaseStorage::getMultiple()
  2. 10 core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php \Drupal\Core\KeyValueStore\DatabaseStorage::getMultiple()
  3. 11.x core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php \Drupal\Core\KeyValueStore\DatabaseStorage::getMultiple()

Overrides KeyValueStoreInterface::getMultiple

1 method overrides DatabaseStorage::getMultiple()
DatabaseStorageExpirable::getMultiple in core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
Returns the stored key/value pairs for a given set of keys.

File

core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php, line 73

Class

DatabaseStorage
Defines a default key/value store implementation.

Namespace

Drupal\Core\KeyValueStore

Code

public function getMultiple(array $keys) {
    $values = [];
    try {
        $result = $this->connection
            ->query('SELECT name, value FROM {' . $this->connection
            ->escapeTable($this->table) . '} WHERE name IN ( :keys[] ) AND collection = :collection', [
            ':keys[]' => $keys,
            ':collection' => $this->collection,
        ])
            ->fetchAllAssoc('name');
        foreach ($keys as $key) {
            if (isset($result[$key])) {
                $values[$key] = $this->serializer
                    ->decode($result[$key]->value);
            }
        }
    } 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.
    }
    return $values;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.