You are here

public function MongodbFlood::isAllowed in MongoDB 8

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

Overrides FloodInterface::isAllowed

File

src/MongodbFlood.php, line 79
Definition of Drupal\mongodb\MongodbFlood.

Class

MongodbFlood
Defines the mongodb flood backend.

Namespace

Drupal\mongodb

Code

public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) {
  if (!isset($identifier)) {
    $identifier = $this
      ->request()
      ->getClientIp();
  }
  $key = array(
    'event' => $name,
    'identifier' => $identifier,
    'timestamp' => array(
      '$gt' => REQUEST_TIME - $window,
    ),
    'expiration' => array(
      '$gt' => REQUEST_TIME,
    ),
  );
  return $this->mongo
    ->get('flood')
    ->count($key) < $threshold;
}