function MemoryBackend::isAllowed
Same name in other branches
- 9 core/lib/Drupal/Core/Flood/MemoryBackend.php \Drupal\Core\Flood\MemoryBackend::isAllowed()
- 8.9.x core/lib/Drupal/Core/Flood/MemoryBackend.php \Drupal\Core\Flood\MemoryBackend::isAllowed()
- 10 core/lib/Drupal/Core/Flood/MemoryBackend.php \Drupal\Core\Flood\MemoryBackend::isAllowed()
Overrides FloodInterface::isAllowed
File
-
core/
lib/ Drupal/ Core/ Flood/ MemoryBackend.php, line 76
Class
- MemoryBackend
- Defines the memory flood backend. This is used for testing.
Namespace
Drupal\Core\FloodCode
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 ($entry) use ($limit) {
return $entry['time'] > $limit;
}));
return $number < $threshold;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.