You are here

public function ExpiredCollector::collect in Simple OAuth (OAuth2) & OpenID Connect 5.x

Same name and namespace in other branches
  1. 8.4 src/ExpiredCollector.php \Drupal\simple_oauth\ExpiredCollector::collect()
  2. 8.2 src/ExpiredCollector.php \Drupal\simple_oauth\ExpiredCollector::collect()
  3. 8.3 src/ExpiredCollector.php \Drupal\simple_oauth\ExpiredCollector::collect()

Collect all expired token ids.

Parameters

int $limit: Number of tokens to fetch.

Return value

\Drupal\simple_oauth\Entity\Oauth2TokenInterface[] The expired tokens.

File

src/ExpiredCollector.php, line 62

Class

ExpiredCollector
Service in charge of deleting or expiring tokens that cannot be used anymore.

Namespace

Drupal\simple_oauth

Code

public function collect($limit = 0) {
  $query = $this->tokenStorage
    ->getQuery();
  $query
    ->condition('expire', $this->dateTime
    ->getRequestTime(), '<');

  // If limit available.
  if (!empty($limit)) {
    $query
      ->range(0, $limit);
  }
  if (!($results = $query
    ->execute())) {
    return [];
  }
  return array_values($this->tokenStorage
    ->loadMultiple(array_values($results)));
}