Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3f949af

Browse filesBrowse files
committed
minor #20869 [RateLimiter] deprecate injecting RateLimiterFactory (kbond)
This PR was merged into the 7.3 branch. Discussion ---------- [RateLimiter] deprecate injecting `RateLimiterFactory` Closes #20865. Commits ------- fff5293 [RateLimiter] deprecate injecting `RateLimiterFactory`
2 parents 56c81f5 + fff5293 commit 3f949af
Copy full SHA for 3f949af

File tree

1 file changed

+12
-6
lines changed
Filter options

1 file changed

+12
-6
lines changed

‎rate_limiter.rst

Copy file name to clipboardExpand all lines: rate_limiter.rst
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ prevents that number from being higher than 5,000).
230230
Rate 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+
233239
After having installed and configured the rate limiter, inject it in any service
234240
or controller and call the ``consume()`` method to try to consume a given number
235241
of 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.