Example #1
0
 public function __invoke(Request $request, Application $app)
 {
     $flap = new Flap(new FlapsStorage($app['database']), 'api');
     $flap->pushThrottlingStrategy(new LeakyBucketStrategy(50, '1m'));
     if ($flap->isViolator($request->getClientIp())) {
         throw new TooManyRequestsException('You have reached the maximum allowed number of requests per minute. Calm down, buddy.');
     }
 }
Example #2
0
 public function limit(Entity $entity)
 {
     $this->flap->limit($entity->id);
 }