W3cubDocs

/Drupal 8

public function DatabaseBackend::register

public DatabaseBackend::register($name, $window = 3600, $identifier = NULL)

Registers an event for the current visitor to the flood control mechanism.

Parameters

string $name: The name of an event. To prevent unintended name clashes, it is recommended to use the module name first in the event name, optionally followed by a dot and the actual event name (e.g. "mymodule.my_event").

int $window: (optional) Number of seconds before this event expires. Defaults to 3600 (1 hour). Typically uses the same value as the isAllowed() $window parameter. Expired events are purged on cron run to prevent the flood table from growing indefinitely.

string $identifier: (optional) Unique identifier of the current user. Defaults to the current user's IP address).

Overrides FloodInterface::register

File

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

Class

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

Namespace

Drupal\Core\Flood

Code

public function register($name, $window = 3600, $identifier = NULL) {
  if (!isset($identifier)) {
    $identifier = $this->requestStack->getCurrentRequest()->getClientIp();
  }
  $try_again = FALSE;
  try {
    $this->doInsert($name, $window, $identifier);
  }
  catch (\Exception $e) {
    $try_again = $this->ensureTableExists();
    if (!$try_again) {
      throw $e;
    }
  }
  if ($try_again) {
    $this->doInsert($name, $window, $identifier);
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Flood!DatabaseBackend.php/function/DatabaseBackend::register/8.1.x