RateLimitGlobal.php in RESTful 7.2
File
src/Plugin/rate_limit/RateLimitGlobal.php
View source
<?php
namespace Drupal\restful\Plugin\rate_limit;
use Drupal\Component\Plugin\PluginBase;
use Drupal\restful\Http\RequestInterface;
class RateLimitGlobal extends RateLimit {
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'));
}
public function generateIdentifier($account = NULL) {
$identifier = '';
$identifier .= $this
->getPluginId() . PluginBase::DERIVATIVE_SEPARATOR;
$identifier .= empty($account->uid) ? ip_address() : $account->uid;
return $identifier;
}
public function getLimit($account = NULL) {
return reset($this->limits);
}
public function isRequestedEvent(RequestInterface $request) {
return $this
->getLimit() > 0;
}
}
Classes
Name |
Description |
RateLimitGlobal |
Class RateLimitGlobal
@package Drupal\restful\Plugin\rate_limit |