Skip to content

Commit 5aececa

Browse files
committed
feature #38562 [RateLimiter] Added reserve() to LimiterInterface and rename Limiter to RateLimiter (wouterj)
This PR was squashed before being merged into the 5.x branch. Discussion ---------- [RateLimiter] Added reserve() to LimiterInterface and rename Limiter to RateLimiter | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - While Javier wrote documentation for this new component, we found a couple of confusing elements that might need some tweaks: * The `Limiter` class (previously called `LimiterFactory`) has imho a bit strange name, as it's not a limiter and it doesn't implement `LimiterInterface`. It can only new limiters. I believe `LimiterFactory` - like `LockFactory` - would be the most clear, but as that was rejected before, here is another proposal using `RateLimiter`. * `reserve()` was now only part of the token bucket implementation. That made it a bit less useful. I think I've found a way to also allow reserving future hits in the fixed window implementation, so I've moved it to the `LimiterInterface`. Commits ------- cd34f21254 [RateLimiter] Added reserve() to LimiterInterface and rename Limiter to RateLimiter
2 parents e6304b2 + b4920e9 commit 5aececa

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@
128128
use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
129129
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
130130
use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
131-
use Symfony\Component\RateLimiter\Limiter;
132131
use Symfony\Component\RateLimiter\LimiterInterface;
132+
use Symfony\Component\RateLimiter\RateLimiter;
133133
use Symfony\Component\RateLimiter\Storage\CacheStorage;
134134
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
135135
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
@@ -2267,7 +2267,7 @@ public static function registerRateLimiter(ContainerBuilder $container, string $
22672267
$limiterConfig['id'] = $name;
22682268
$limiter->replaceArgument(0, $limiterConfig);
22692269

2270-
$container->registerAliasForArgument($limiterId, Limiter::class, $name.'.limiter');
2270+
$container->registerAliasForArgument($limiterId, RateLimiter::class, $name.'.limiter');
22712271
}
22722272

22732273
private function resolveTrustedHeaders(array $headers): int

Resources/config/rate_limiter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14-
use Symfony\Component\RateLimiter\Limiter;
14+
use Symfony\Component\RateLimiter\RateLimiter;
1515

1616
return static function (ContainerConfigurator $container) {
1717
$container->services()
1818
->set('cache.rate_limiter')
1919
->parent('cache.app')
2020
->tag('cache.pool')
2121

22-
->set('limiter', Limiter::class)
22+
->set('limiter', RateLimiter::class)
2323
->abstract()
2424
->args([
2525
abstract_arg('config'),

0 commit comments

Comments
 (0)