You are here

class RateLimit in RESTful 7.2

Same name in this branch
  1. 7.2 src/Annotation/RateLimit.php \Drupal\restful\Annotation\RateLimit
  2. 7.2 src/RateLimit/Entity/RateLimit.php \Drupal\restful\RateLimit\Entity\RateLimit
  3. 7.2 src/Plugin/rate_limit/RateLimit.php \Drupal\restful\Plugin\rate_limit\RateLimit

Hierarchy

  • class \Drupal\restful\RateLimit\Entity\RateLimit extends \Drupal\restful\RateLimit\Entity\Entity

Expanded class hierarchy of RateLimit

File

src/RateLimit/Entity/RateLimit.php, line 10
Contains Drupal\restful\RateLimit\Entity\RateLimit.

Namespace

Drupal\restful\RateLimit\Entity
View source
class RateLimit extends \Entity {

  /**
   * Number of hits.
   *
   * @var int
   */
  public $hits = 0;

  /**
   * Expiration timestamp.
   *
   * @var int
   */
  public $expiration = 0;

  /**
   * Saves an extra hit.
   */
  public function hit() {
    $this->hits++;
    $this
      ->save();
  }

  /**
   * Checks if the entity is expired.
   */
  public function isExpired() {
    return REQUEST_TIME > $this->expiration;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RateLimit::$expiration public property Expiration timestamp.
RateLimit::$hits public property Number of hits.
RateLimit::hit public function Saves an extra hit.
RateLimit::isExpired public function Checks if the entity is expired.