Skip to content

Commit 3974926

Browse files
committed
feature symfony#58939 [RateLimiter] Add RateLimiterFactoryInterface (alexandre-daubois)
This PR was merged into the 7.3 branch. Discussion ---------- [RateLimiter] Add `RateLimiterFactoryInterface` | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix symfony#58920 | License | MIT I think it makes sense to create this interface for both being able to implement your own factory logic as well as type-hint against an interface when injecting it. I would however not make the class non-final as suggested in the issue. The interface only contains one method with not that much logic inside the current implementation. Commits ------- 619c0eb [RateLimiter] Add `RateLimiterFactoryInterface`
2 parents c4ee8fd + 619c0eb commit 3974926

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* Add JsonEncoder services and configuration
1010
* Add new `framework.property_info.with_constructor_extractor` option to allow enabling or disabling the constructor extractor integration
1111
* Deprecate the `--show-arguments` option of the `container:debug` command, as arguments are now always shown
12+
* Add `RateLimiterFactoryInterface` as an alias of the `limiter` service
1213

1314
7.2
1415
---

src/Symfony/Bundle/FrameworkBundle/Resources/config/rate_limiter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

1414
use Symfony\Component\RateLimiter\RateLimiterFactory;
15+
use Symfony\Component\RateLimiter\RateLimiterFactoryInterface;
1516

1617
return static function (ContainerConfigurator $container) {
1718
$container->services()
@@ -27,4 +28,9 @@
2728
null,
2829
])
2930
;
31+
32+
if (interface_exists(RateLimiterFactoryInterface::class)) {
33+
$container->services()
34+
->alias(RateLimiterFactoryInterface::class, 'limiter');
35+
}
3036
};

src/Symfony/Component/RateLimiter/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add `RateLimiterFactoryInterface`
8+
49
6.4
510
---
611

src/Symfony/Component/RateLimiter/RateLimiterFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* @author Wouter de Jong <[email protected]>
2626
*/
27-
final class RateLimiterFactory
27+
final class RateLimiterFactory implements RateLimiterFactoryInterface
2828
{
2929
private array $config;
3030

@@ -53,7 +53,7 @@ public function create(?string $key = null): LimiterInterface
5353
};
5454
}
5555

56-
protected static function configureOptions(OptionsResolver $options): void
56+
private static function configureOptions(OptionsResolver $options): void
5757
{
5858
$intervalNormalizer = static function (Options $options, string $interval): \DateInterval {
5959
// Create DateTimeImmutable from unix timesatmp, so the default timezone is ignored and we don't need to
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\RateLimiter;
13+
14+
/**
15+
* @author Alexandre Daubois <[email protected]>
16+
*/
17+
interface RateLimiterFactoryInterface
18+
{
19+
/**
20+
* @param string|null $key an optional key used to identify the limiter
21+
*/
22+
public function create(?string $key = null): LimiterInterface;
23+
}

0 commit comments

Comments
 (0)