public function MemoryBackend::isAllowed in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Flood/MemoryBackend.php \Drupal\Core\Flood\MemoryBackend::isAllowed()
- 9 core/lib/Drupal/Core/Flood/MemoryBackend.php \Drupal\Core\Flood\MemoryBackend::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\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;
}