function MemoryBackend::isAllowed

Same name in other branches
  1. 9 core/lib/Drupal/Core/Flood/MemoryBackend.php \Drupal\Core\Flood\MemoryBackend::isAllowed()
  2. 10 core/lib/Drupal/Core/Flood/MemoryBackend.php \Drupal\Core\Flood\MemoryBackend::isAllowed()
  3. 11.x core/lib/Drupal/Core/Flood/MemoryBackend.php \Drupal\Core\Flood\MemoryBackend::isAllowed()

Overrides FloodInterface::isAllowed

File

core/lib/Drupal/Core/Flood/MemoryBackend.php, line 60

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->requestStack
            ->getCurrentRequest()
            ->getClientIp();
    }
    if (!isset($this->events[$name][$identifier])) {
        return $threshold > 0;
    }
    $limit = microtime(TRUE) - $window;
    $number = count(array_filter($this->events[$name][$identifier], function ($timestamp) use ($limit) {
        return $timestamp > $limit;
    }));
    return $number < $threshold;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.