Skip to content

Commit 8222bf4

Browse files
committed
Merge remote-tracking branch 'origin/1.x' into update-1-to-2
2 parents c6c246f + 14b673c commit 8222bf4

29 files changed

+159
-27
lines changed

.github/workflows/continuous-integration.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- dependencies: "php-http/guzzle7-adapter"
3535
php-version: "8.2"
3636
symfony-deprecations-helper: "weak"
37-
- dependencies: "php-http/guzzle7-adapter"
37+
- dependencies: "php-http/guzzle7-adapter php-http/throttle-plugin"
3838
php-version: "8.3"
3939
symfony-deprecations-helper: "weak"
4040

@@ -69,7 +69,7 @@ jobs:
6969

7070
steps:
7171
- name: "Checkout"
72-
uses: "actions/checkout@v3"
72+
uses: "actions/checkout@v4"
7373
with:
7474
fetch-depth: 2
7575

@@ -79,18 +79,18 @@ jobs:
7979
php-version: "${{ matrix.php-version }}"
8080
coverage: "pcov"
8181
ini-values: "zend.assertions=1"
82+
tools: "flex"
8283

8384
- name: "Enforce using stable dependencies"
8485
run: "composer config minimum-stability stable"
8586
if: "${{ matrix.stability == 'stable' }}"
8687

8788
- name: "Add dependencies and enable flex"
8889
run: |
89-
composer require --no-update symfony/flex ${{ matrix.dependencies }}
90-
composer config --no-plugins allow-plugins.symfony/flex true
90+
composer require --no-update ${{ matrix.dependencies }}
9191
9292
- name: "Install dependencies with Composer"
93-
uses: "ramsey/composer-install@v2"
93+
uses: "ramsey/composer-install@v3"
9494
with:
9595
dependency-versions: "${{ matrix.dependency-versions }}"
9696
composer-options: "${{ matrix.composer-options }}"

.github/workflows/php-cs-fixer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
steps:
1717
- name: "Checkout"
18-
uses: "actions/checkout@v3"
18+
uses: "actions/checkout@v4"
1919
- name: "PHP-CS-Fixer"
2020
uses: "docker://oskarstark/php-cs-fixer-ga:3.26.0"
2121
with:

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/.phpunit.result.cache
2-
/.php_cs.cache
2+
/.php-cs-fixer.cache
33
/behat.yml
44
/build/
55
/composer.lock

CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
2020

2121
# Version 1
2222

23+
# 1.34.3 - 2024-09-01
24+
25+
- Same as 1.34.2 but tagged on the 1.x banch instead of the feature branch.
26+
27+
# 1.34.2 - 2024-09-01
28+
29+
- More cleanup of the rate-limiter configuration. The service name is the full service name of the rate limiter, e.g. `limiter.my_name` when configuring `framework.rate_limiter.my_name`.
30+
31+
# 1.34.1 - 2024-09-01
32+
33+
- The rate-limiter name in the throttle plugin configuration is required.
34+
35+
# 1.34.0 - 2024-06-17
36+
37+
- Support to configure the throttle plugin.
38+
39+
# 1.33.1 - 2024-05-27
40+
41+
- Fixed extension to depend on the DependencyInjection component rather than the HttpKernel.
42+
2343
# 1.33.0 - 2024-02-27
2444

2545
- Support php-http/cache-plugin 2.0 and bump minimal version to 1.7 by defaulting the stream factory for cache to `httplug.psr17_stream_factory` (#448).

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@
4747
"php-http/curl-client": "<2.0",
4848
"php-http/socket-client": "<2.0",
4949
"kriswallsmith/buzz": "<0.17",
50-
"php-http/react-adapter": "<3.0"
50+
"php-http/react-adapter": "<3.0",
51+
"php-http/throttle-plugin": "<1.1"
5152
},
5253
"require-dev": {
5354
"guzzlehttp/psr7": "^1.7 || ^2.0",
5455
"matthiasnoback/symfony-config-test": "^5.2",
55-
"matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0",
56+
"matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0",
5657
"nyholm/nsa": "^1.1",
5758
"nyholm/psr7": "^1.2.1",
5859
"php-http/cache-plugin": "^1.7",
@@ -64,7 +65,6 @@
6465
"symfony/dom-crawler": "^6.4 || ^7.1",
6566
"symfony/framework-bundle": "^6.4 || ^7.1",
6667
"symfony/http-foundation": "^6.4 || ^7.1",
67-
"symfony/phpunit-bridge": "^7.1",
6868
"symfony/stopwatch": "^6.4 || ^7.1",
6969
"symfony/twig-bundle": "^6.4 || ^7.1",
7070
"symfony/web-profiler-bundle": "^6.4 || ^7.1",
@@ -97,7 +97,7 @@
9797
},
9898
"prefer-stable": false,
9999
"scripts": {
100-
"test": "vendor/bin/simple-phpunit",
101-
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
100+
"test": "vendor/bin/phpunit",
101+
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
102102
}
103103
}

src/ClientFactory/AutoDiscoveryFactory.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Use auto discovery to find a HTTP client.
1111
*
1212
* @author Tobias Nyholm <[email protected]>
13+
*
14+
* @final
1315
*/
1416
class AutoDiscoveryFactory implements ClientFactory
1517
{

src/ClientFactory/BuzzFactory.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
/**
1212
* @author Tobias Nyholm <[email protected]>
13+
*
14+
* @final
1315
*/
1416
class BuzzFactory implements ClientFactory
1517
{

src/ClientFactory/CurlFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
/**
1212
* @author Tobias Nyholm <[email protected]>
13+
*
14+
* @final
1315
*/
1416
class CurlFactory implements ClientFactory
1517
{
1618
public function __construct(
1719
private readonly ResponseFactoryInterface $responseFactory,
18-
private readonly StreamFactoryInterface $streamFactory
20+
private readonly StreamFactoryInterface $streamFactory,
1921
) {
2022
}
2123

src/ClientFactory/Guzzle6Factory.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/**
1010
* @author Tobias Nyholm <[email protected]>
11+
*
12+
* @final
1113
*/
1214
class Guzzle6Factory implements ClientFactory
1315
{

src/ClientFactory/Guzzle7Factory.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/**
1010
* @author Tobias Nyholm <[email protected]>
11+
*
12+
* @final
1113
*/
1214
class Guzzle7Factory implements ClientFactory
1315
{

src/ClientFactory/ReactFactory.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/**
1010
* @author Tobias Nyholm <[email protected]>
11+
*
12+
* @final
1113
*/
1214
class ReactFactory implements ClientFactory
1315
{

src/ClientFactory/SocketFactory.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/**
1010
* @author Tobias Nyholm <[email protected]>
11+
*
12+
* @final
1113
*/
1214
class SocketFactory implements ClientFactory
1315
{

src/ClientFactory/SymfonyFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
/**
1313
* @author Tobias Nyholm <[email protected]>
14+
*
15+
* @final
1416
*/
1517
class SymfonyFactory implements ClientFactory
1618
{
1719
public function __construct(
1820
private readonly ResponseFactoryInterface $responseFactory,
19-
private readonly StreamFactoryInterface $streamFactory
21+
private readonly StreamFactoryInterface $streamFactory,
2022
) {
2123
}
2224

src/Collector/Collector.php

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* @author Fabien Bourigault <[email protected]>
1919
*
2020
* @internal
21+
*
22+
* @final
2123
*/
2224
class Collector extends DataCollector
2325
{

src/Collector/Formatter.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @author Fabien Bourigault <[email protected]>
2020
*
2121
* @internal
22+
*
23+
* @final
2224
*/
2325
class Formatter implements MessageFormatter
2426
{

src/Collector/PluginClientFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class PluginClientFactory
2323
public function __construct(
2424
private readonly Collector $collector,
2525
private readonly Formatter $formatter,
26-
private readonly Stopwatch $stopwatch
26+
private readonly Stopwatch $stopwatch,
2727
) {
2828
}
2929

src/Collector/ProfileClient.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* @author Fabien Bourigault <[email protected]>
2222
*
2323
* @internal
24+
*
25+
* @final
2426
*/
2527
class ProfileClient implements ClientInterface, HttpAsyncClient
2628
{
@@ -40,7 +42,7 @@ public function __construct(
4042
$client,
4143
private readonly Collector $collector,
4244
private readonly Formatter $formatter,
43-
private readonly Stopwatch $stopwatch
45+
private readonly Stopwatch $stopwatch,
4446
) {
4547
if (!($client instanceof ClientInterface && $client instanceof HttpAsyncClient)) {
4648
$client = new FlexibleHttpClient($client);

src/Collector/ProfileClientFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* @author Fabien Bourigault <[email protected]>
1717
*
1818
* @internal
19+
*
20+
* @final
1921
*/
2022
class ProfileClientFactory implements ClientFactory
2123
{
@@ -28,7 +30,7 @@ public function __construct(
2830
ClientFactory|callable $factory,
2931
private readonly Collector $collector,
3032
private readonly Formatter $formatter,
31-
private readonly Stopwatch $stopwatch
33+
private readonly Stopwatch $stopwatch,
3234
) {
3335
$this->factory = $factory;
3436
}

src/Collector/ProfilePlugin.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* @author Fabien Bourigault <[email protected]>
1616
*
1717
* @internal
18+
*
19+
* @final
1820
*/
1921
class ProfilePlugin implements Plugin
2022
{
@@ -74,7 +76,7 @@ private function onException(
7476
RequestInterface $request,
7577
Profile $profile,
7678
\Exception $exception,
77-
Stack $stack
79+
Stack $stack,
7880
): void {
7981
$profile->setFailed(true);
8082
$profile->setResponse($this->formatter->formatException($exception));

src/Collector/StackPlugin.php

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* @author Fabien Bourigault <[email protected]>
1616
*
1717
* @internal
18+
*
19+
* @final
1820
*/
1921
class StackPlugin implements Plugin
2022
{

src/Collector/Twig/HttpMessageMarkupExtension.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* @author Tobias Nyholm <[email protected]>
16+
*
17+
* @final
1618
*/
1719
class HttpMessageMarkupExtension extends AbstractExtension
1820
{

src/DependencyInjection/Configuration.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*
3232
* @author David Buchmann <[email protected]>
3333
* @author Tobias Nyholm <[email protected]>
34+
*
35+
* @final
3436
*/
3537
class Configuration implements ConfigurationInterface
3638
{
@@ -593,14 +595,38 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, bool $dis
593595
->end();
594596
// End stopwatch plugin
595597

596-
$error = $children->arrayNode('error')
598+
$children->arrayNode('error')
597599
->canBeEnabled()
598600
->addDefaultsIfNotSet()
599601
->children()
600602
->scalarNode('only_server_exception')->defaultFalse()->end()
601603
->end()
602604
->end();
603605
// End error plugin
606+
607+
$children->arrayNode('throttle')
608+
->canBeEnabled()
609+
->addDefaultsIfNotSet()
610+
->children()
611+
->scalarNode('name')
612+
->isRequired()
613+
->info('Rate limiter service name from symfony/rate-limiter configuration. E.g. for a rate limiter http_client you specify limiter.http_client here')
614+
->end()
615+
->scalarNode('key')
616+
->defaultNull()
617+
->info('Key to avoid sharing this rate limiter with other clients or other services. You can use the name of the client for example.')
618+
->end()
619+
->integerNode('tokens')
620+
->defaultValue(1)
621+
->info('How many tokens spending per request')
622+
->end()
623+
->floatNode('max_time')
624+
->defaultNull()
625+
->info('Maximum accepted waiting time in seconds')
626+
->end()
627+
->end()
628+
->end();
629+
// End throttle plugin
604630
}
605631

606632
/**

src/DependencyInjection/HttplugExtension.php

+22
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Http\Client\Common\HttpMethodsClient;
1111
use Http\Client\Common\HttpMethodsClientInterface;
1212
use Http\Client\Common\Plugin\AuthenticationPlugin;
13+
use Http\Client\Common\Plugin\ThrottlePlugin;
1314
use Http\Client\Common\PluginClient;
1415
use Http\Client\Common\PluginClientFactory;
1516
use Http\Client\HttpAsyncClient;
@@ -33,11 +34,14 @@
3334
use Symfony\Component\DependencyInjection\Extension\Extension;
3435
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
3536
use Symfony\Component\DependencyInjection\Reference;
37+
use Symfony\Component\RateLimiter\LimiterInterface;
3638
use Twig\Environment as TwigEnvironment;
3739

3840
/**
3941
* @author David Buchmann <[email protected]>
4042
* @author Tobias Nyholm <[email protected]>
43+
*
44+
* @final
4145
*/
4246
class HttplugExtension extends Extension
4347
{
@@ -279,6 +283,24 @@ private function configurePluginByName(string $name, Definition $definition, arr
279283

280284
break;
281285

286+
case 'throttle':
287+
if (!\class_exists(ThrottlePlugin::class)) {
288+
throw new InvalidConfigurationException('You need to require the Throttle Plugin to be able to use it: "composer require php-http/throttle-plugin".');
289+
}
290+
291+
$limiterServiceId = $serviceId.'.'.$config['name'];
292+
$container
293+
->register($limiterServiceId, LimiterInterface::class)
294+
->setFactory([new Reference($config['name']), 'create'])
295+
->addArgument($config['key'])
296+
->setPublic(false);
297+
298+
$definition->replaceArgument(0, new Reference($limiterServiceId));
299+
$definition->setArgument('$tokens', $config['tokens']);
300+
$definition->setArgument('$maxTime', $config['max_time']);
301+
302+
break;
303+
282304
/* client specific plugins */
283305

284306
case 'add_host':

0 commit comments

Comments
 (0)