interface FloodInterface

Same name in other branches
  1. 9 core/lib/Drupal/Core/Flood/FloodInterface.php \Drupal\Core\Flood\FloodInterface
  2. 10 core/lib/Drupal/Core/Flood/FloodInterface.php \Drupal\Core\Flood\FloodInterface
  3. 11.x core/lib/Drupal/Core/Flood/FloodInterface.php \Drupal\Core\Flood\FloodInterface

Defines an interface for flood controllers.

Hierarchy

Expanded class hierarchy of FloodInterface

All classes that implement FloodInterface

6 files declare their use of FloodInterface
BasicAuth.php in core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php
MessageForm.php in core/modules/contact/src/MessageForm.php
UserAuthenticationController.php in core/modules/user/src/Controller/UserAuthenticationController.php
UserController.php in core/modules/user/src/Controller/UserController.php
UserLoginForm.php in core/modules/user/src/Form/UserLoginForm.php

... See full list

File

core/lib/Drupal/Core/Flood/FloodInterface.php, line 8

Namespace

Drupal\Core\Flood
View source
interface FloodInterface {
    
    /**
     * Registers an event for the current visitor to the flood control mechanism.
     *
     * @param 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").
     * @param 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.
     * @param string $identifier
     *   (optional) Unique identifier of the current user. Defaults to the current
     *   user's IP address).
     */
    public function register($name, $window = 3600, $identifier = NULL);
    
    /**
     * Makes the flood control mechanism forget an event for the current visitor.
     *
     * @param string $name
     *   The name of an event.
     * @param string $identifier
     *   (optional) Unique identifier of the current user. Defaults to the current
     *   user's IP address).
     */
    public function clear($name, $identifier = NULL);
    
    /**
     * Checks whether a user is allowed to proceed with the specified event.
     *
     * Events can have thresholds saying that each user can only do that event
     * a certain number of times in a time window. This function verifies that
     * the current user has not exceeded this threshold.
     *
     * @param string $name
     *   The name of an event.
     * @param int $threshold
     *   The maximum number of times each user can do this event per time window.
     * @param int $window
     *   (optional) Number of seconds in the time window for this event (default is 3600
     *   seconds, or 1 hour).
     * @param string $identifier
     *   (optional) Unique identifier of the current user. Defaults to the current
     *   user's IP address).
     *
     * @return
     *   TRUE if the user is allowed to proceed. FALSE if they have exceeded the
     *   threshold and should not be allowed to proceed.
     */
    public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL);
    
    /**
     * Cleans up expired flood events. This method is called automatically on
     * cron run.
     *
     * @see system_cron()
     */
    public function garbageCollection();

}

Members

Title Sort descending Modifiers Object type Summary Overrides
FloodInterface::clear public function Makes the flood control mechanism forget an event for the current visitor. 2
FloodInterface::garbageCollection public function Cleans up expired flood events. This method is called automatically on
cron run.
2
FloodInterface::isAllowed public function Checks whether a user is allowed to proceed with the specified event. 2
FloodInterface::register public function Registers an event for the current visitor to the flood control mechanism. 2

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