Skip to content

Commit 2c96225

Browse files
committed
minor #15155 Update rate_limiter.rst (igancev)
This PR was merged into the 5.2 branch. Discussion ---------- Update rate_limiter.rst Inject HttpFoundation $request in action of controller <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `5.x` for features of unreleased versions). --> Commits ------- 1cc3689 Update rate_limiter.rst
2 parents 30aea31 + 1cc3689 commit 2c96225

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rate_limiter.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,15 @@ the number of requests to the API::
167167
namespace App\Controller;
168168

169169
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
170+
use Symfony\Component\HttpFoundation\Request;
170171
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
171172
use Symfony\Component\RateLimiter\RateLimiterFactory;
172173

173174
class ApiController extends AbstractController
174175
{
175176
// if you're using service autowiring, the variable name must be:
176177
// "rate limiter name" (in camelCase) + "Limiter" suffix
177-
public function index(RateLimiterFactory $anonymousApiLimiter)
178+
public function index(Request $request, RateLimiterFactory $anonymousApiLimiter)
178179
{
179180
// create a limiter based on a unique identifier of the client
180181
// (e.g. the client's IP address, a username/email, an API key, etc.)
@@ -272,12 +273,13 @@ the :class:`Symfony\\Component\\RateLimiter\\Reservation` object returned by the
272273
namespace App\Controller;
273274

274275
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
276+
use Symfony\Component\HttpFoundation\Request;
275277
use Symfony\Component\HttpFoundation\Response;
276278
use Symfony\Component\RateLimiter\RateLimiterFactory;
277279

278280
class ApiController extends AbstractController
279281
{
280-
public function index(RateLimiterFactory $anonymousApiLimiter)
282+
public function index(Request $request, RateLimiterFactory $anonymousApiLimiter)
281283
{
282284
$limiter = $anonymousApiLimiter->create($request->getClientIp());
283285
$limit = $limiter->consume();

0 commit comments

Comments
 (0)