3 namespace Drupal\Core\Flood;
6 * Defines an interface for flood controllers.
8 interface FloodInterface {
11 * Registers an event for the current visitor to the flood control mechanism.
14 * The name of an event. To prevent unintended name clashes, it is recommended
15 * to use the module name first in the event name, optionally followed by
16 * a dot and the actual event name (e.g. "mymodule.my_event").
18 * (optional) Number of seconds before this event expires. Defaults to 3600
19 * (1 hour). Typically uses the same value as the isAllowed() $window
20 * parameter. Expired events are purged on cron run to prevent the flood
21 * table from growing indefinitely.
22 * @param string $identifier
23 * (optional) Unique identifier of the current user. Defaults to the current
26 public function register($name, $window = 3600, $identifier = NULL);
29 * Makes the flood control mechanism forget an event for the current visitor.
32 * The name of an event.
33 * @param string $identifier
34 * (optional) Unique identifier of the current user. Defaults to the current
37 public function clear($name, $identifier = NULL);
40 * Checks whether a user is allowed to proceed with the specified event.
42 * Events can have thresholds saying that each user can only do that event
43 * a certain number of times in a time window. This function verifies that
44 * the current user has not exceeded this threshold.
47 * The name of an event.
48 * @param int $threshold
49 * The maximum number of times each user can do this event per time window.
51 * (optional) Number of seconds in the time window for this event (default is 3600
52 * seconds, or 1 hour).
53 * @param string $identifier
54 * (optional) Unique identifier of the current user. Defaults to the current
58 * TRUE if the user is allowed to proceed. FALSE if they have exceeded the
59 * threshold and should not be allowed to proceed.
61 public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL);
64 * Cleans up expired flood events. This method is called automatically on
69 public function garbageCollection();