public function RateLimit::getLimit in RESTful 7.2
Get the rate limit. Returns the highest rate limit for the current account.
Parameters
object $account: The account object for the user making the request.
Return value
int The limit.
Overrides RateLimitInterface::getLimit
1 method overrides RateLimit::getLimit()
- RateLimitGlobal::getLimit in src/
Plugin/ rate_limit/ RateLimitGlobal.php - All limits are the same for the global limit. Return the first one.
File
- src/
Plugin/ rate_limit/ RateLimit.php, line 62 - Contains \Drupal\restful\Plugin\rate_limit\RateLimit
Class
Namespace
Drupal\restful\Plugin\rate_limitCode
public function getLimit($account = NULL) {
// If the user is anonymous.
if (empty($account->roles)) {
return $this->limits['anonymous user'];
}
// If the user is logged then return the best limit for all the roles the
// user has.
$max_limit = 0;
foreach ($account->roles as $rid => $role) {
if (!isset($this->limits[$role])) {
// No limit configured for this role.
continue;
}
if ($this->limits[$role] < $max_limit && $this->limits[$role] != RateLimitManager::UNLIMITED_RATE_LIMIT) {
// The limit is smaller than one previously found.
continue;
}
// This is the highest limit for the current user given all their roles.
$max_limit = $this->limits[$role];
}
return $max_limit;
}