public function DatabaseStorage::getMultiple

public DatabaseStorage::getMultiple(array $keys)

Returns the stored key/value pairs for a given set of keys.

@todo What's returned for non-existing keys?

Parameters

array $keys: A list of keys to retrieve.

Return value

array An associative array of items successfully returned, indexed by key.

Overrides KeyValueStoreInterface::getMultiple

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 = array();
  try {
    $result = $this->connection->query('SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE name IN ( :keys[] ) AND collection = :collection', array(':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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!KeyValueStore!DatabaseStorage.php/function/DatabaseStorage::getMultiple/8.1.x