Skip to content

Commit a14d2ef

Browse files
committed
Make an example more realistic
1 parent ca659f9 commit a14d2ef

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

rate_limiter.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,19 @@ the number of requests to the API::
143143
In other scenarios you may want instead to wait as long as needed until a new
144144
token is available. In those cases, use the ``wait()`` method::
145145

146-
// src/Controller/LuckyController.php
147-
// ...
146+
// src/Controller/ApiController.php
147+
namespace App\Controller;
148+
149+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
150+
use Symfony\Component\HttpFoundation\Request;
151+
use Symfony\Component\RateLimiter\Limiter;
148152

149153
class ApiController extends AbstractController
150154
{
151-
public function registerUser(LimiterInterface $authenticatedApiLimiter)
155+
public function registerUser(Request $request, Limiter $authenticatedApiLimiter)
152156
{
153-
$limiter = $authenticatedApiLimiter->create($request->getClientIp());
157+
$apiKey = $request->headers->get('apikey');
158+
$limiter = $authenticatedApiLimiter->create($apiKey);
154159

155160
// this blocks the application until the given number of tokens can be consumed
156161
do {

0 commit comments

Comments
 (0)