You are here

public function DatabaseStorageSortedBase::getRange in Key-value Extensions 8

Parameters

float $start:

float $stop:

boolean $inclusive:

Return value

array

Overrides KeyValueStoreSortedInterface::getRange

File

src/KeyValueStore/DatabaseStorageSortedBase.php, line 51

Class

DatabaseStorageSortedBase

Namespace

Drupal\key_value\KeyValueStore

Code

public function getRange($start, $stop = NULL, $inclusive = TRUE) {
  $query = $this->connection
    ->select($this->table, 't')
    ->fields('t', [
    'value',
  ])
    ->condition('collection', $this->collection)
    ->condition('name', $start, $inclusive ? '>=' : '>');
  if ($stop !== NULL) {
    $query
      ->condition('name', $stop, $inclusive ? '<=' : '<');
  }
  $result = $query
    ->orderBy('name', 'ASC')
    ->execute();
  $values = [];
  foreach ($result as $item) {
    $values[] = $this->serializer
      ->decode($item->value);
  }
  return $values;
}