class RateLimitGlobal in RESTful 7.2
Class RateLimitGlobal @package Drupal\restful\Plugin\rate_limit
Plugin annotation
@RateLimit(
id = "global",
label = "Global limitation",
description = "This keeps a count across all the handlers.",
)
Hierarchy
- class \Drupal\restful\Plugin\rate_limit\RateLimit extends \Drupal\Component\Plugin\PluginBase implements RateLimitInterface
- class \Drupal\restful\Plugin\rate_limit\RateLimitGlobal
Expanded class hierarchy of RateLimitGlobal
File
- src/
Plugin/ rate_limit/ RateLimitGlobal.php, line 22 - Contains \Drupal\restful\Plugin\rate_limit\RateLimitGlobal
Namespace
Drupal\restful\Plugin\rate_limitView source
class RateLimitGlobal extends RateLimit {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$limit = variable_get('restful_global_rate_limit', 0);
foreach (user_roles() as $rid => $role_info) {
$this->limits[$rid] = $limit;
}
$this->period = new \DateInterval(variable_get('restful_global_rate_period', 'P1D'));
}
/**
* {@inheritdoc}
*/
public function generateIdentifier($account = NULL) {
$identifier = '';
$identifier .= $this
->getPluginId() . PluginBase::DERIVATIVE_SEPARATOR;
$identifier .= empty($account->uid) ? ip_address() : $account->uid;
return $identifier;
}
/**
* {@inheritdoc}
*
* All limits are the same for the global limit. Return the first one.
*/
public function getLimit($account = NULL) {
return reset($this->limits);
}
/**
* {@inheritdoc}
*
* Only track the global limit for the current user if the variable is on.
*/
public function isRequestedEvent(RequestInterface $request) {
return $this
->getLimit() > 0;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RateLimit:: |
protected | property | Array of maximum limit of requests across all endpoints per role. | |
RateLimit:: |
protected | property | Period after which the rate limit is expired. | |
RateLimit:: |
protected | property | The resource this object is limiting access to. | |
RateLimit:: |
public | function |
Get the rate limit period. Overrides RateLimitInterface:: |
|
RateLimit:: |
public | function |
Load rate limit entity. Overrides RateLimitInterface:: |
|
RateLimit:: |
public | function |
Set the rate limit. Overrides RateLimitInterface:: |
|
RateLimit:: |
public | function |
Set the rate limit period. Overrides RateLimitInterface:: |
|
RateLimitGlobal:: |
public | function |
Generates an identifier for the event and the request. Overrides RateLimit:: |
|
RateLimitGlobal:: |
public | function |
All limits are the same for the global limit. Return the first one. Overrides RateLimit:: |
|
RateLimitGlobal:: |
public | function |
Only track the global limit for the current user if the variable is on. Overrides RateLimitInterface:: |
|
RateLimitGlobal:: |
public | function |
Overrides RateLimit:: |