Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DatabaseBackend.php

function DatabaseBackend::isAllowed

Overrides FloodInterface::isAllowed

File

core/lib/Drupal/Core/Flood/DatabaseBackend.php, line 119

Class

DatabaseBackend
Defines the database flood backend. This is the default Drupal backend.

Namespace

Drupal\Core\Flood

Code

public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) {
    if (!isset($identifier)) {
        $identifier = $this->requestStack
            ->getCurrentRequest()
            ->getClientIp();
    }
    try {
        $number = $this->connection
            ->select(static::TABLE_NAME, 'f')
            ->condition('event', $name)
            ->condition('identifier', $identifier)
            ->condition('timestamp', $this->time
            ->getRequestTime() - $window, '>')
            ->countQuery()
            ->execute()
            ->fetchField();
        return $number < $threshold;
    } catch (\Exception $e) {
        if (!$this->ensureTableExists()) {
            throw $e;
        }
        return TRUE;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal