You are here

public function DatabaseStorage::getAll in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php \Drupal\Core\KeyValueStore\DatabaseStorage::getAll()

Returns all stored key/value pairs in the collection.

Return value

array An associative array containing all stored items in the collection.

Overrides KeyValueStoreInterface::getAll

1 method overrides DatabaseStorage::getAll()
DatabaseStorageExpirable::getAll in core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
Returns all stored key/value pairs in the collection.

File

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

Class

DatabaseStorage
Defines a default key/value store implementation.

Namespace

Drupal\Core\KeyValueStore

Code

public function getAll() {
  try {
    $result = $this->connection
      ->query('SELECT [name], [value] FROM {' . $this->connection
      ->escapeTable($this->table) . '} WHERE [collection] = :collection', [
      ':collection' => $this->collection,
    ]);
  } catch (\Exception $e) {
    $this
      ->catchException($e);
    $result = [];
  }
  $values = [];
  foreach ($result as $item) {
    if ($item) {
      $values[$item->name] = $this->serializer
        ->decode($item->value);
    }
  }
  return $values;
}