You are here

class RateLimitDecoratedResource in RESTful 7.2

Class RateLimitDecoratedResource.

@package Drupal\restful\Plugin\resource\Decorators

Hierarchy

Expanded class hierarchy of RateLimitDecoratedResource

1 file declares its use of RateLimitDecoratedResource
restful.module in ./restful.module

File

src/Plugin/resource/Decorators/RateLimitDecoratedResource.php, line 18
Contains \Drupal\restful\Plugin\resource\Decorators\RateLimitDecoratedResource

Namespace

Drupal\restful\Plugin\resource\Decorators
View source
class RateLimitDecoratedResource extends ResourceDecoratorBase implements ResourceDecoratorInterface {

  /**
   * Authentication manager.
   *
   * @var RateLimitManager
   */
  protected $rateLimitManager;

  /**
   * Constructs a Drupal\Component\Plugin\PluginBase object.
   *
   * @param ResourceInterface $subject
   *   The decorated object.
   * @param RateLimitManager $rate_limit_manager
   *   Injected rate limit manager.
   */
  public function __construct(ResourceInterface $subject, RateLimitManager $rate_limit_manager = NULL) {
    $this->subject = $subject;
    $plugin_definition = $subject
      ->getPluginDefinition();
    $rate_limit_info = empty($plugin_definition['rateLimit']) ? array() : $plugin_definition['rateLimit'];
    if ($limit = variable_get('restful_global_rate_limit', 0)) {
      $rate_limit_info['global'] = array(
        'period' => variable_get('restful_global_rate_period', 'P1D'),
        'limits' => array(),
      );
      foreach (user_roles() as $role_name) {
        $rate_limit_info['global']['limits'][$role_name] = $limit;
      }
    }
    $this->rateLimitManager = $rate_limit_manager ? $rate_limit_manager : new RateLimitManager($this, $rate_limit_info);
  }

  /**
   * Setter for $rateLimitManager.
   *
   * @param RateLimitManager $rate_limit_manager
   *   The rate limit manager.
   */
  protected function setRateLimitManager(RateLimitManager $rate_limit_manager) {
    $this->rateLimitManager = $rate_limit_manager;
  }

  /**
   * Getter for $rate_limit_manager.
   *
   * @return RateLimitManager
   *   The rate limit manager.
   */
  protected function getRateLimitManager() {
    return $this->rateLimitManager;
  }

  /**
   * {@inheritdoc}
   */
  public function process() {

    // This will throw the appropriate exception if needed.
    $this
      ->getRateLimitManager()
      ->checkRateLimit($this
      ->getRequest());
    return $this->subject
      ->process();
  }

  /**
   * {@inheritdoc}
   */
  public function setAccount($account) {
    $this->subject
      ->setAccount($account);
    $this->rateLimitManager
      ->setAccount($account);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RateLimitDecoratedResource::$rateLimitManager protected property Authentication manager.
RateLimitDecoratedResource::getRateLimitManager protected function Getter for $rate_limit_manager.
RateLimitDecoratedResource::process public function Controller function that passes the data along and executes right action. Overrides ResourceDecoratorBase::process
RateLimitDecoratedResource::setAccount public function Overrides ResourceDecoratorBase::setAccount
RateLimitDecoratedResource::setRateLimitManager protected function Setter for $rateLimitManager.
RateLimitDecoratedResource::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object.
ResourceDecoratorBase::$subject protected property The decorated resource.
ResourceDecoratorBase::access public function Determine if user can access the handler. Overrides ResourceInterface::access
ResourceDecoratorBase::calculateDependencies public function
ResourceDecoratorBase::controllersInfo public function Gets the controllers. Overrides ResourceInterface::controllersInfo
ResourceDecoratorBase::create public function Basic implementation for create. Overrides ResourceInterface::create
ResourceDecoratorBase::dataProviderFactory public function Data provider factory. Overrides ResourceInterface::dataProviderFactory 1
ResourceDecoratorBase::defaultConfiguration public function
ResourceDecoratorBase::disable public function Disable the resource. Overrides ResourceInterface::disable 1
ResourceDecoratorBase::discover public function Discovery controller callback. Overrides ResourceInterface::discover
ResourceDecoratorBase::doDelete public function Shorthand method to perform a quick DELETE request. Overrides ResourceInterface::doDelete
ResourceDecoratorBase::doGet public function Shorthand method to perform a quick GET request. Overrides ResourceInterface::doGet
ResourceDecoratorBase::doPatch public function Shorthand method to perform a quick PATCH request. Overrides ResourceInterface::doPatch
ResourceDecoratorBase::doPost public function Shorthand method to perform a quick POST request. Overrides ResourceInterface::doPost
ResourceDecoratorBase::doPut public function Shorthand method to perform a quick PUT request. Overrides ResourceInterface::doPut
ResourceDecoratorBase::doWrite private function
ResourceDecoratorBase::enable public function Enable the resource. Overrides ResourceInterface::enable 1
ResourceDecoratorBase::getAccount public function Get the user from for request. Overrides ResourceInterface::getAccount
ResourceDecoratorBase::getConfiguration public function
ResourceDecoratorBase::getControllerFromPath public function Return the controller for a given path. Overrides ResourceInterface::getControllerFromPath
ResourceDecoratorBase::getControllers public function Gets the controllers for this resource. Overrides ResourceInterface::getControllers
ResourceDecoratorBase::getDataProvider public function Gets the data provider. Overrides ResourceInterface::getDataProvider 1
ResourceDecoratorBase::getDecoratedResource public function Gets the decorated resource. Overrides ResourceDecoratorInterface::getDecoratedResource
ResourceDecoratorBase::getFieldDefinitions public function Gets the field definitions. Overrides ResourceInterface::getFieldDefinitions 1
ResourceDecoratorBase::getPath public function Gets the path of the resource. Overrides ResourceInterface::getPath 1
ResourceDecoratorBase::getPluginDefinition public function This is a decorated resource, get proxy the request until you reach the annotated resource. 1
ResourceDecoratorBase::getPluginId public function
ResourceDecoratorBase::getPrimaryResource public function Gets the primary resource, the one that is not a decorator. Overrides ResourceDecoratorInterface::getPrimaryResource
ResourceDecoratorBase::getRequest public function Get the request object. Overrides ResourceInterface::getRequest
ResourceDecoratorBase::getResourceMachineName public function Gets the resource machine name. Overrides ResourceInterface::getResourceMachineName 1
ResourceDecoratorBase::getResourceName public function Gets the resource name. Overrides ResourceInterface::getResourceName
ResourceDecoratorBase::getUrl public function Helper method; Get the URL of the resource and query strings. Overrides ResourceInterface::getUrl
ResourceDecoratorBase::getVersion public function Return array keyed with the major and minor version of the resource. Overrides ResourceInterface::getVersion
ResourceDecoratorBase::index public function Basic implementation for listing. Overrides ResourceInterface::index 1
ResourceDecoratorBase::isEnabled public function Checks if the resource is enabled. Overrides ResourceInterface::isEnabled 1
ResourceDecoratorBase::isInstanceOf public function Checks if the decorated object is an instance of something. Overrides ExplorableDecoratorInterface::isInstanceOf
ResourceDecoratorBase::remove public function Basic implementation for update. Overrides ResourceInterface::remove 1
ResourceDecoratorBase::replace public function Basic implementation for update. Overrides ResourceInterface::replace 1
ResourceDecoratorBase::setConfiguration public function
ResourceDecoratorBase::setDataProvider public function Sets the data provider. Overrides ResourceInterface::setDataProvider 1
ResourceDecoratorBase::setFieldDefinitions public function Sets the field definitions. Overrides ResourceInterface::setFieldDefinitions
ResourceDecoratorBase::setPath public function Sets the path of the resource. Overrides ResourceInterface::setPath 1
ResourceDecoratorBase::setPluginDefinition public function This is a decorated resource, set proxy the request until you reach the annotated resource. Overrides ResourceInterface::setPluginDefinition
ResourceDecoratorBase::setRequest public function Sets the request object. Overrides ResourceInterface::setRequest
ResourceDecoratorBase::switchUserBack public function Switches the user back from the original user for the session. Overrides ResourceInterface::switchUserBack
ResourceDecoratorBase::update public function Basic implementation for update. Overrides ResourceInterface::update 1
ResourceDecoratorBase::versionedUrl public function Gets a resource URL based on the current version. Overrides ResourceInterface::versionedUrl
ResourceDecoratorBase::view public function Basic implementation for view. Overrides ResourceInterface::view 1
ResourceDecoratorBase::__call public function If any method not declared, then defer it to the decorated field.
ResourceInterface::IDS_SEPARATOR constant The string that separates multiple ids.