From e6b3699ce383687fcff5ad28f564dc1c4e51f9a9 Mon Sep 17 00:00:00 2001 From: Nathan Salter Date: Sat, 11 Jun 2022 09:23:51 +0100 Subject: [PATCH] Update to use `RateLimiterFactoryInterface` As proposed in https://github.com/symfony/symfony/issues/46644 simply add a new interface so alternative approaches or unit testing components with the factory is possible. --- rate_limiter.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rate_limiter.rst b/rate_limiter.rst index 07db8c9c204..a3cf08ba262 100644 --- a/rate_limiter.rst +++ b/rate_limiter.rst @@ -223,13 +223,13 @@ the number of requests to the API:: use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException; - use Symfony\Component\RateLimiter\RateLimiterFactory; + use Symfony\Component\RateLimiter\RateLimiterFactoryInterface; class ApiController extends AbstractController { // if you're using service autowiring, the variable name must be: // "rate limiter name" (in camelCase) + "Limiter" suffix - public function index(Request $request, RateLimiterFactory $anonymousApiLimiter) + public function index(Request $request, RateLimiterFactoryInterface $anonymousApiLimiter) { // create a limiter based on a unique identifier of the client // (e.g. the client's IP address, a username/email, an API key, etc.) @@ -274,7 +274,7 @@ using the ``reserve()`` method:: class ApiController extends AbstractController { - public function registerUser(Request $request, RateLimiterFactory $authenticatedApiLimiter) + public function registerUser(Request $request, RateLimiterFactoryInterface $authenticatedApiLimiter) { $apiKey = $request->headers->get('apikey'); $limiter = $authenticatedApiLimiter->create($apiKey); @@ -329,11 +329,11 @@ the :class:`Symfony\\Component\\RateLimiter\\Reservation` object returned by the use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; - use Symfony\Component\RateLimiter\RateLimiterFactory; + use Symfony\Component\RateLimiter\RateLimiterFactoryInterface; class ApiController extends AbstractController { - public function index(Request $request, RateLimiterFactory $anonymousApiLimiter) + public function index(Request $request, RateLimiterFactoryInterface $anonymousApiLimiter) { $limiter = $anonymousApiLimiter->create($request->getClientIp()); $limit = $limiter->consume();