getRateLimit() public method

Get the rate limit for this route.
public getRateLimit ( ) : integer
return integer
Example #1
0
 public function testControllerOptionsMergeAndOverrideRouteOptions()
 {
     $request = Request::create('foo', 'GET');
     $route = new Route($this->adapter, $this->container, $request, ['uri' => 'foo', 'methods' => ['GET', 'HEAD'], 'action' => ['scopes' => ['foo', 'bar'], 'providers' => ['foo'], 'limit' => 5, 'expires' => 10, 'throttle' => 'Foo', 'version' => ['v1'], 'conditionalRequest' => false, 'uses' => 'Dingo\\Api\\Tests\\Stubs\\RoutingControllerStub@index']]);
     $this->assertEquals(['foo', 'bar', 'baz', 'bing'], $route->scopes(), 'Route did not setup scopes correctly.');
     $this->assertEquals(['foo', 'red', 'black'], $route->getAuthProviders(), 'Route did not setup authentication providers correctly.');
     $this->assertEquals(10, $route->getRateLimit(), 'Route did not setup rate limit correctly.');
     $this->assertEquals(20, $route->getRateExpiration(), 'Route did not setup rate limit expiration correctly.');
     $this->assertTrue($route->hasThrottle(), 'Route did not setup throttle correctly.');
     $this->assertInstanceOf('Dingo\\Api\\Tests\\Stubs\\BasicThrottleStub', $route->getThrottle(), 'Route did not setup throttle correctly.');
 }
Example #2
0
 /**
  * Perform rate limiting before a request is executed.
  *
  * @param \Dingo\Api\Routing\Route $route
  * @param \Illuminate\Http\Request $request
  * @param int                      $limit
  * @param int                      $expires
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  *
  * @return mixed
  */
 public function filter(Route $route, Request $request, $limit = 0, $expires = 0)
 {
     if ($this->requestIsInternal($request)) {
         return;
     }
     $limit = $route->getRateLimit($limit);
     $expires = $route->getLimitExpiration($expires);
     $this->limiter->rateLimitRequest($request, $limit, $expires);
     if (!$this->limiter->requestWasRateLimited()) {
         return;
     }
     $this->attachAfterFilter();
     if ($this->limiter->exceededRateLimit()) {
         throw new AccessDeniedHttpException();
     }
 }
Example #3
0
 /**
  * Display the routes rate limiting requests per second. This takes the limit
  * and divides it by the expiration time in seconds to give you a rough
  * idea of how many requests you'd be able to fire off per second
  * on the route.
  *
  * @param \Dingo\Api\Routing\Route $route
  *
  * @return null|string
  */
 protected function routeRateLimit($route)
 {
     list($limit, $expires) = [$route->getRateLimit(), $route->getRateLimitExpiration()];
     if ($limit && $expires) {
         return sprintf('%s req/s', round($limit / ($expires * 60), 2));
     }
 }