8000 bug #38675 [RateLimiter] Rename RateLimiter to RateLimiterFactory (Ny… · symfony/symfony@1c81aa7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c81aa7

Browse files
committed
bug #38675 [RateLimiter] Rename RateLimiter to RateLimiterFactory (Nyholm)
This PR was squashed before being merged into the 5.x branch. Discussion ---------- [RateLimiter] Rename RateLimiter to RateLimiterFactory | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | No, not released yet | Tickets | | License | MIT | Doc PR | should be added Sorry for making a few BC breaks. @wouterj [said](#38562 (comment)) that this class was suggested to be named `LimiterFactory` before. But that was rejected. Just my looking at the names of the classes we currently have: - Rate - RateLimit - RateLimiter I find it hard to know what these are doing and the difference between them. Note that none of them are used as a rate limiter (ie implements `LimiterInterface`) I would like to be clear that a `RateLimiterFactory` is used to create an object implementing `LimiterInterface`. Commits ------- 8be261b [RateLimiter] Rename RateLimiter to RateLimiterFactory
2 parents d1c5739 + 8be261b commit 1c81aa7

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
133133
use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
134134
use Symfony\Component\RateLimiter\LimiterInterface;
135-
use Symfony\Component\RateLimiter\RateLimiter;
135+
use Symfony\Component\RateLimiter\RateLimiterFactory;
136136
use Symfony\Component\RateLimiter\Storage\CacheStorage;
137137
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
138138
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
@@ -2280,7 +2280,7 @@ public static function registerRateLimiter(ContainerBuilder $container, string $
22802280
$limiterConfig['id'] = $name;
22812281
$limiter->replaceArgument(0, $limiterConfig);
22822282

2283-
$container->registerAliasForArgument($limiterId, RateLimiter::class, $name.'.limiter');
2283+
$container->registerAliasForArgument($limiterId, RateLimiterFactory::class, $name.'.limiter');
22842284
}
22852285

22862286
private function resolveTrustedHeaders(array $headers): int

src/Symfony/Bundle/FrameworkBundle/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\RateLimiter;
14+
use Symfony\Component\RateLimiter\RateLimiterFactory;
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', RateLimiter::class)
22+
->set('limiter', RateLimiterFactory::class)
2323
->abstract()
2424
->args([
2525
abstract_arg('config'),

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\DependencyInjection\Reference;
2020
use Symfony\Component\HttpFoundation\RateLimiter\RequestRateLimiterInterface;
21-
use Symfony\Component\RateLimiter\RateLimiter;
21+
use Symfony\Component\RateLimiter\RateLimiterFactory;
2222
use Symfony\Component\Security\Http\EventListener\LoginThrottlingListener;
2323
use Symfony\Component\Security\Http\RateLimiter\DefaultLoginRateLimiter;
2424

@@ -63,7 +63,7 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal
6363
throw new \LogicException('Login throttling requires symfony/security-http:^5.2.');
6464
}
6565

66-
if (!class_exists(RateLimiter::class)) {
66+
if (!class_exists(RateLimiterFactory::class)) {
6767
throw new \LogicException('Login throttling requires symfony/rate-limiter to be installed and enabled.');
6868
}
6969

src/Symfony/Component/RateLimiter/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ $ composer require symfony/rate-limiter
1818

1919
```php
2020
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
21-
use Symfony\Component\RateLimiter\RateLimiter;
21+
use Symfony\Component\RateLimiter\RateLimiterFactory;
2222

23-
$limiter = new RateLimiter([
23+
$limiter = new RateLimiterFactory([
2424
'id' => 'login',
25-
'strategy' => 'token_bucket', // or 'fixed_window'
25+
'strategy' => 'token_bucket',
2626
'limit' => 10,
2727
'rate' => ['interval' => '15 minutes'],
2828
], new InMemoryStorage());

src/Symfony/Component/RateLimiter/RateLimiter.php renamed to src/Symfony/Component/RateLimiter/RateLimiterFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @experimental in 5.2
2424
*/
25-
final class RateLimiter
25+
final class RateLimiterFactory
2626
{
2727
private $config;
2828
private $storage;

src/Symfony/Component/RateLimiter/Tests/LimiterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Lock\LockFactory;
1616
use Symfony\Component\RateLimiter\FixedWindowLimiter;
17-
use Symfony\Component\RateLimiter\RateLimiter;
17+
use Symfony\Component\RateLimiter\RateLimiterFactory;
1818
use Symfony\Component\RateLimiter\Storage\StorageInterface;
1919
use Symfony\Component\RateLimiter\TokenBucketLimiter;
2020

@@ -61,6 +61,6 @@ public function testWrongInterval()
6161

6262
private function createFactory(array $options)
6363
{
64-
return new RateLimiter($options, $this->createMock(StorageInterface::class), $this->createMock(LockFactory::class));
64+
return new RateLimiterFactory($options, $this->createMock(StorageInterface::class), $this->createMock(LockFactory::class));
6565
}
6666
}

src/Symfony/Component/RateLimiter/Tests/RateLimiterTest.php renamed to src/Symfony/Component/RateLimiter/Tests/RateLimiterFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
1616
use Symfony\Component\RateLimiter\FixedWindowLimiter;
1717
use Symfony\Component\RateLimiter\NoLimiter;
18-
use Symfony\Component\RateLimiter\RateLimiter;
18+
use Symfony\Component\RateLimiter\RateLimiterFactory;
1919
use Symfony\Component\RateLimiter\SlidingWindowLimiter;
2020
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
2121
use Symfony\Component\RateLimiter\TokenBucketLimiter;
2222

23-
class RateLimiterTest extends TestCase
23+
class RateLimiterFactoryTest extends TestCase
2424
{
2525
/**
2626
* @dataProvider validConfigProvider
2727
*/
2828
public function testValidConfig(string $expectedClass, array $config)
2929
{
30-
$factory = new RateLimiter($config, new InMemoryStorage());
30+
$factory = new RateLimiterFactory($config, new InMemoryStorage());
3131
$rateLimiter = $factory->create('key');
3232
$this->assertInstanceOf($expectedClass, $rateLimiter);
3333
}
@@ -66,7 +66,7 @@ public function validConfigProvider()
6666
public function testInvalidConfig(string $exceptionClass, array $config)
6767
{
6868
$this->expectException($exceptionClass);
69-
$factory = new RateLimiter($config, new InMemoryStorage());
69+
$factory = new RateLimiterFactory($config, new InMemoryStorage());
7070
$factory->create('key');
7171
}
7272

src/Symfony/Component/Security/Http/RateLimiter/DefaultLoginRateLimiter.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\RateLimiter\AbstractRequestRateLimiter;
1515
use Symfony\Component\HttpFoundation\Request;
16-
use Symfony\Component\RateLimiter\RateLimiter;
16+
use Symfony\Component\RateLimiter\RateLimiterFactory;
1717
use Symfony\Component\Security\Core\Security;
1818

1919
/**
@@ -28,20 +28,20 @@
2828
*/
2929
final class DefaultLoginRateLimiter extends AbstractRequestRateLimiter
3030
{
31-
private $globalLimiter;
32-
private $localLimiter;
31+
private $globalFactory;
32+
private $localFactory;
3333

34-
public function __construct(RateLimiter $globalLimiter, RateLimiter $localLimiter)
34+
public function __construct(RateLimiterFactory $globalFactory, RateLimiterFactory $localFactory)
3535
{
36-
$this->globalLimiter = $globalLimiter;
37-
$this->localLimiter = $localLimiter;
36+
$this->globalFactory = $globalFactory;
37+
$this->localFactory = $localFactory;
3838
}
3939

4040
protected function getLimiters(Request $request): array
4141
{
4242
return [
43-
$this->globalLimiter->create($request->getClientIp()),
44-
$this->localLimiter->create($request->attributes->get 1241 (Security::LAST_USERNAME).$request->getClientIp()),
43+
$this->globalFactory->create($request->getClientIp()),
44+
$this->localFactory->create($request->attributes->get(Security::LAST_USERNAME).$request->getClientIp()),
4545
];
4646
}
4747
}

src/Symfony/Component/Security/Http/Tests/EventListener/LoginThrottlingListenerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\RequestStack;
17-
use Symfony\Component\RateLimiter\RateLimiter;
17+
use Symfony\Component\RateLimiter\RateLimiterFactory;
1818
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
1919
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2020
use Symfony\Component\Security\Core\Exception\TooManyLoginAttemptsAuthenticationException;
@@ -35,13 +35,13 @@ protected function setUp(): void
3535
{
3636
$this->requestStack = new RequestStack();
3737

38-
$localLimiter = new RateLimiter([
38+
$localLimiter = new RateLimiterFactory([
3939
'id' => 'login',
4040
'strategy' => 'fixed_window',
4141
'limit' => 3,
4242
'interval' => '1 minute',
4343
], new InMemoryStorage());
44-
$globalLimiter = new RateLimiter([
44+
$globalLimiter = new RateLimiterFactory([
4545
'id' => 'login',
4646
'strategy' => 'fixed_window',
4747
'limit' => 6,

0 commit comments

Comments
 (0)
0