FloodInterface.php 2.4 KB

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