You are here

public static function Flood::isAllowed in Acquia Search 3.x

Determines if a request can be sent via the flood control mechanism.

Parameters

string $request_type: The incoming request type.

Return value

bool If the request is allowed

Throws

\Exception

1 call to Flood::isAllowed()
SearchSubscriber::preExecuteRequest in src/EventSubscriber/SearchSubscriber.php
Build Acquia Search Solr Authenticator.

File

src/Helper/Flood.php, line 116

Class

Flood
Class Flood.

Namespace

Drupal\acquia_search\Helper

Code

public static function isAllowed(string $request_type) : bool {

  // Allow all requests from types that aren't controlled.
  if (!self::isControlled($request_type)) {
    return TRUE;
  }

  // Use the Drupal Flood service to check if we can run this request.
  $is_allowed = \Drupal::flood()
    ->isAllowed('acquia_search', self::getConfigValue($request_type, 'limit'), self::getConfigValue($request_type, 'window'), $request_type);

  // If this request should be blocked, log if needed and return.
  if (!$is_allowed) {
    self::logFloodLimit($request_type);
    return FALSE;
  }

  // Log the allowed request into the Flood service.
  \Drupal::flood()
    ->register('acquia_search', self::getConfigValue($request_type, 'window'), $request_type);
  return TRUE;
}