@@ -230,6 +230,12 @@ prevents that number from being higher than 5,000).
230230Rate Limiting in Action
231231-----------------------
232232
233+ .. versionadded :: 7.3
234+
235+ :class: `Symfony\\ Component\\ RateLimiter\\ RateLimiterFactoryInterface ` was
236+ added and should now be used for autowiring instead of
237+ :class: `Symfony\\ Component\\ RateLimiter\\ RateLimiterFactory `.
238+
233239After having installed and configured the rate limiter, inject it in any service
234240or controller and call the ``consume() `` method to try to consume a given number
235241of tokens. For example, this controller uses the previous rate limiter to control
@@ -242,13 +248,13 @@ the number of requests to the API::
242248 use Symfony\Component\HttpFoundation\Request;
243249 use Symfony\Component\HttpFoundation\Response;
244250 use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
245- use Symfony\Component\RateLimiter\RateLimiterFactory ;
251+ use Symfony\Component\RateLimiter\RateLimiterFactoryInterface ;
246252
247253 class ApiController extends AbstractController
248254 {
249255 // if you're using service autowiring, the variable name must be:
250256 // "rate limiter name" (in camelCase) + "Limiter" suffix
251- public function index(Request $request, RateLimiterFactory $anonymousApiLimiter): Response
257+ public function index(Request $request, RateLimiterFactoryInterface $anonymousApiLimiter): Response
252258 {
253259 // create a limiter based on a unique identifier of the client
254260 // (e.g. the client's IP address, a username/email, an API key, etc.)
@@ -291,11 +297,11 @@ using the ``reserve()`` method::
291297 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
292298 use Symfony\Component\HttpFoundation\Request;
293299 use Symfony\Component\HttpFoundation\Response;
294- use Symfony\Component\RateLimiter\RateLimiterFactory ;
300+ use Symfony\Component\RateLimiter\RateLimiterFactoryInterface ;
295301
296302 class ApiController extends AbstractController
297303 {
298- public function registerUser(Request $request, RateLimiterFactory $authenticatedApiLimiter): Response
304+ public function registerUser(Request $request, RateLimiterFactoryInterface $authenticatedApiLimiter): Response
299305 {
300306 $apiKey = $request->headers->get('apikey');
301307 $limiter = $authenticatedApiLimiter->create($apiKey);
@@ -350,11 +356,11 @@ the :class:`Symfony\\Component\\RateLimiter\\Reservation` object returned by the
350356 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
351357 use Symfony\Component\HttpFoundation\Request;
352358 use Symfony\Component\HttpFoundation\Response;
353- use Symfony\Component\RateLimiter\RateLimiterFactory ;
359+ use Symfony\Component\RateLimiter\RateLimiterFactoryInterface ;
354360
355361 class ApiController extends AbstractController
356362 {
357- public function index(Request $request, RateLimiterFactory $anonymousApiLimiter): Response
363+ public function index(Request $request, RateLimiterFactoryInterface $anonymousApiLimiter): Response
358364 {
359365 $limiter = $anonymousApiLimiter->create($request->getClientIp());
360366 $limit = $limiter->consume();
0 commit comments