You are here

public function RateLimitManager::__construct in RESTful 7.2

Constructor for RateLimitManager.

Parameters

ResourceInterface $resource: Resource being checked.

array $plugin_options: Array of options keyed by plugin id.

object $account: The identified user account for the request.

RateLimitPluginManager $manager: The plugin manager.

File

src/RateLimit/RateLimitManager.php, line 74
Contains \Drupal\restful\RateLimit\RateLimitManager

Class

RateLimitManager

Namespace

Drupal\restful\RateLimit

Code

public function __construct(ResourceInterface $resource, array $plugin_options, $account = NULL, RateLimitPluginManager $manager = NULL) {
  $this->resource = $resource;
  $account = $account ? $account : $resource
    ->getAccount();
  $this->account = $account ? $account : drupal_anonymous_user();
  $manager = $manager ?: RateLimitPluginManager::create();
  $options = array();
  foreach ($plugin_options as $plugin_id => $rate_options) {

    // Set the instance id to articles::request and specify the plugin id.
    $instance_id = $resource
      ->getResourceName() . PluginBase::DERIVATIVE_SEPARATOR . $plugin_id;
    $options[$instance_id] = array(
      'id' => $plugin_id,
      'resource' => $resource,
    );
    $options[$instance_id] += $rate_options;
  }
  $this->plugins = new RateLimitPluginCollection($manager, $options);
}