10000 [FrameworkBundle][RateLimiter] add `rate_limiter` tag to rate limiter services by kbond · Pull Request #53091 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle][RateLimiter] add rate_limiter tag to rate limiter services #53091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* Move the Router `cache_dir` to `kernel.build_dir`
* Deprecate the `router.cache_dir` config option
* Add `rate_limiter` tags to rate limiter services

7.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2860,7 +2860,8 @@ private function registerRateLimiterConfiguration(array $config, ContainerBuilde
// default configuration (when used by other DI extensions)
$limiterConfig += ['lock_factory' => 'lock.factory', 'cache_pool' => 'cache.rate_limiter'];

$limiter = $container->setDefinition($limiterId = 'limiter.'.$name, new ChildDefinition('limiter'));
$limiter = $container->setDefinition($limiterId = 'limiter.'.$name, new ChildDefinition('limiter'))
->addTag('rate_limiter', ['name' => $name]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think name is the standard tag index we use now or am I mistaken?


if (null !== $limiterConfig['lock_factory']) {
if (!interface_exists(LockInterface::class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,24 @@ public function testRateLimiterLockFactory()

$container->getDefinition('limiter.without_lock')->getArgument(2);
}

public function testRateLimiterIsTagged()
{
$container = $this->createContainerFromClosure(function (ContainerBuilder $container) {
$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'handle_all_throwables' => true,
'php_errors' => ['log' => true],
'lock' => true,
'rate_limiter' => [
'first' => ['policy' => 'fixed_window', 'limit' => 10, 'interval' => '1 hour'],
'second' => ['policy' => 'fixed_window', 'limit' => 10, 'interval' => '1 hour'],
],
]);
});

$this->assertSame('first', $container->getDefinition('limiter.first')->getTag('rate_limiter')[0]['name']);
$this->assertSame('second', $container->getDefinition('limiter.second')->getTag('rate_limiter')[0]['name']);
}
}
0