public function testConstructionWithMethods() { $annot = new RateLimit(array('limit' => 1234, 'period' => 1000, 'methods' => array('POST', 'GET'))); $this->assertCount(2, $annot->getMethods()); $annot->setMethods(array()); $this->assertCount(0, $annot->getMethods()); }
private function getKey(FilterControllerEvent $event, RateLimit $rateLimit, array $annotations) { $request = $event->getRequest(); $controller = $event->getController(); $rateLimitMethods = join("", $rateLimit->getMethods()); $rateLimitAlias = count($annotations) === 0 ? $this->pathLimitProcessor->getMatchedPath($request) : get_class($controller[0]) . ':' . $controller[1]; // Create an initial key by joining the methods and the alias $key = $rateLimitMethods . ':' . $rateLimitAlias; // Let listeners manipulate the key $keyEvent = new GenerateKeyEvent($event->getRequest(), $key); $this->eventDispatcher->dispatch(RateLimitEvents::GENERATE_KEY, $keyEvent); return $keyEvent->getKey(); }