You are here

public function RateLimitDecoratedResource::__construct in RESTful 7.2

Constructs a Drupal\Component\Plugin\PluginBase object.

Parameters

ResourceInterface $subject: The decorated object.

RateLimitManager $rate_limit_manager: Injected rate limit manager.

File

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

Class

RateLimitDecoratedResource
Class RateLimitDecoratedResource.

Namespace

Drupal\restful\Plugin\resource\Decorators

Code

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);
}