You are here

class RestfulRateLimitGlobal in RESTful 7

@file Contains RestfulRateLimitGlobal

Hierarchy

Expanded class hierarchy of RestfulRateLimitGlobal

1 string reference to 'RestfulRateLimitGlobal'
global.inc in plugins/rate_limit/global.inc

File

plugins/rate_limit/RestfulRateLimitGlobal.class.php, line 8
Contains RestfulRateLimitGlobal

View source
class RestfulRateLimitGlobal extends \RestfulRateLimitBase {

  /**
   * {@inheritdoc}
   */
  public function __construct(array $plugin_info, $resource = NULL) {
    parent::__construct($plugin_info, $resource);
    $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(\stdClass $account = NULL) {
    $identifier = '';
    $identifier .= $this->name . '::';
    $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(\stdClass $account = NULL) {
    return reset($this->limits);
  }

  /**
   * {@inheritdoc}
   *
   * Only track the global limit for the current user if the variable is on.
   */
  public function isRequestedEvent(array $request = array()) {
    return $this
      ->getLimit() > 0;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RestfulRateLimitBase::$limits protected property Array of maximum limit of requests across all endpoints per role.
RestfulRateLimitBase::$name protected property The event name.
RestfulRateLimitBase::$period protected property Period after which the rate limit is expired.
RestfulRateLimitBase::$resource protected property The resource name this object is limiting access to.
RestfulRateLimitBase::getPeriod public function Get the rate limit period.
RestfulRateLimitBase::loadRateLimitEntity public function Load rate limit entity.
RestfulRateLimitBase::setLimit public function Set the rate limit.
RestfulRateLimitBase::setPeriod public function Set the rate limit period.
RestfulRateLimitGlobal::generateIdentifier public function Generates an identifier for the event and the request. Overrides RestfulRateLimitBase::generateIdentifier
RestfulRateLimitGlobal::getLimit public function All limits are the same for the global limit. Return the first one. Overrides RestfulRateLimitBase::getLimit
RestfulRateLimitGlobal::isRequestedEvent public function Only track the global limit for the current user if the variable is on. Overrides RestfulRateLimitInterface::isRequestedEvent
RestfulRateLimitGlobal::__construct public function Constructor. Overrides RestfulRateLimitBase::__construct