Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[RateLimiter] Add CompoundRateLimiterFactory #59929

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
Mar 21, 2025
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 1 src/Symfony/Component/RateLimiter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Add `RateLimiterFactoryInterface`
* Add `CompoundRateLimiterFactory`

6.4
---
Expand Down
36 changes: 36 additions & 0 deletions 36 src/Symfony/Component/RateLimiter/CompoundRateLimiterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\RateLimiter;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
final class CompoundRateLimiterFactory implements RateLimiterFactoryInterface
{
/**
* @param iterable<RateLimiterFactoryInterface> $rateLimiterFactories
*/
public function __construct(private iterable $rateLimiterFactories)
{
}

public function create(?string $key = null): LimiterInterface
{
$rateLimiters = [];

foreach ($this->rateLimiterFactories as $rateLimiterFactory) {
$rateLimiters[] = $rateLimiterFactory->create($key);
}

return new CompoundLimiter($rateLimiters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\RateLimiter\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\RateLimiter\CompoundLimiter;
use Symfony\Component\RateLimiter\CompoundRateLimiterFactory;
use Symfony\Component\RateLimiter\LimiterInterface;
use Symfony\Component\RateLimiter\RateLimiterFactoryInterface;

class CompoundRateLimiterFactoryTest extends TestCase
{
public function testCreate()
{
$factory1 = $this->createMock(RateLimiterFactoryInterface::class);
$factory1
->method('create')
->with('foo')
->willReturn($this->createMock(LimiterInterface::class))
;
$factory2 = $this->createMock(RateLimiterFactoryInterface::class);
$factory2
->method('create')
->with('foo')
->willReturn($this->createMock(LimiterInterface::class))
;

$compoundFactory = new CompoundRateLimiterFactory([$factory1, $factory2]);

$this->assertInstanceOf(CompoundLimiter::class, $compoundFactory->create('foo'));
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.