Dingo\Api\Http\RateLimit\Handler::exceededRateLimit PHP Method

exceededRateLimit() public method

Determine if the rate limit has been exceeded.
public exceededRateLimit ( ) : boolean
return boolean
    public function exceededRateLimit()
    {
        return $this->requestWasRateLimited() ? $this->retrieve('requests') > $this->throttle->getLimit() : false;
    }

Usage Example

Beispiel #1
0
 /**
  * Perform rate limiting before a request is executed.
  *
  * @param \Dingo\Api\Http\Request $request
  * @param \Closure                $next
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $route = $this->router->getCurrentRoute();
     if ($route->hasThrottle()) {
         $this->handler->setThrottle($route->getThrottle());
     }
     $this->handler->rateLimitRequest($request, $route->getRateLimit(), $route->getRateExpiration());
     if ($this->handler->exceededRateLimit()) {
         throw new HttpException(403, 'You have exceeded your rate limit.', null, $this->getHeaders());
     }
     $response = $next($request);
     if ($this->handler->requestWasRateLimited()) {
         return $this->responseWithHeaders($response);
     }
     return $response;
 }