function UserFloodEvent::__construct

Same name in other branches
  1. 10 core/modules/user/src/Event/UserFloodEvent.php \Drupal\user\Event\UserFloodEvent::__construct()
  2. 11.x core/modules/user/src/Event/UserFloodEvent.php \Drupal\user\Event\UserFloodEvent::__construct()

Constructs a user flood event object.

Parameters

string $name: The name of the flood event.

int $threshold: The threshold for the flood event.

int $window: The window for the flood event.

string $identifier: The identifier of the flood event.

File

core/modules/user/src/Event/UserFloodEvent.php, line 66

Class

UserFloodEvent
Provides a user flood event for event listeners.

Namespace

Drupal\user\Event

Code

public function __construct($name, $threshold, $window, $identifier) {
    $this->name = $name;
    $this->threshold = $threshold;
    $this->window = $window;
    $this->identifier = $identifier;
    // The identifier could be a uid or an IP, or a composite of both.
    if (is_numeric($identifier)) {
        $this->uid = $identifier;
        return;
    }
    if (strpos($identifier, '-') !== FALSE) {
        [
            $uid,
            $ip,
        ] = explode('-', $identifier);
        $this->uid = $uid;
        $this->ip = $ip;
        return;
    }
    $this->ip = $identifier;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.