limiter = $limiter; } /** * Sets the limits to use with the Rate Limiter. * * @param int $tries * @param int $minutes * @return Throttler */ public function throttle(int $tries, int $minutes) { $this->maxAttempts = $tries; $this->decaySeconds = $minutes * 60; return $this; } /** * Sets the target object to throttle its methods. * * @param object $target * @return $this */ public function setTarget(object $target) { $this->target = $target; return $this; } /** * Handle dynamically calling the object. * * @param string $name * @param mixed $arguments * @return object */ public function __call($name, $arguments) { $key = get_class($this->target) . '|' . $name; if (! $this->limiter->tooManyAttempts($key, $this->maxAttempts)) { $this->target->{$name}(...$arguments); $this->limiter->hit($key, $this->decaySeconds); } return $this->target; } }