public function MemoryBackend::isAllowed

Implements Drupal\Core\Flood\FloodInterface::isAllowed().

Overrides FloodInterface::isAllowed

File

drupal/core/lib/Drupal/Core/Flood/MemoryBackend.php, line 65
Definition of Drupal\Core\Flood\MemoryBackend.

Class

MemoryBackend
Defines the memory flood backend. This is used for testing.

Namespace

Drupal\Core\Flood

Code

public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) {
  if (!isset($identifier)) {
    $identifier = $this->request
      ->getClientIP();
  }
  $limit = microtime(true) - $window;
  $number = count(array_filter($this->events[$name][$identifier], function ($timestamp) use ($limit) {
    return $timestamp > $limit;
  }));
  return $number < $threshold;
}