Skip to content

Commit ddf790e

Browse files
committed
Merge remote-tracking branch 'origin/1.x' into 1-to-2
2 parents 734a76e + 5380dad commit ddf790e

File tree

8 files changed

+65
-8
lines changed

8 files changed

+65
-8
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878

7979
steps:
8080
- name: "Checkout"
81-
uses: "actions/checkout@v3"
81+
uses: "actions/checkout@v4"
8282
with:
8383
fetch-depth: 2
8484

@@ -88,18 +88,18 @@ jobs:
8888
php-version: "${{ matrix.php-version }}"
8989
coverage: "pcov"
9090
ini-values: "zend.assertions=1"
91+
tools: "flex"
9192

9293
- name: "Enforce using stable dependencies"
9394
run: "composer config minimum-stability stable"
9495
if: "${{ matrix.stability == 'stable' }}"
9596

9697
- name: "Add dependencies and enable flex"
9798
run: |
98-
composer require --no-update symfony/flex ${{ matrix.dependencies }}
99-
composer config --no-plugins allow-plugins.symfony/flex true
99+
composer require --no-update ${{ matrix.dependencies }}
100100
101101
- name: "Install dependencies with Composer"
102-
uses: "ramsey/composer-install@v2"
102+
uses: "ramsey/composer-install@v3"
103103
with:
104104
dependency-versions: "${{ matrix.dependency-versions }}"
105105
composer-options: "${{ matrix.composer-options }}"

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

Lines changed: 1 addition & 1 deletion
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:2.19.0"
2121
with:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
1919

2020
# Version 1
2121

22+
# 1.34.0 - 2024-06-17
23+
24+
- Support to configure the throttle plugin.
25+
26+
# 1.33.1 - 2024-05-27
27+
28+
- Fixed extension to depend on the DependencyInjection component rather than the HttpKernel.
29+
2230
# 1.33.0 - 2024-02-27
2331

2432
- 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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242
"symfony/options-resolver": "^5.4 || ^6.0 || ^7.0"
4343
},
4444
"conflict": {
45+
"kriswallsmith/buzz": "<0.17",
4546
"php-http/guzzle6-adapter": "<1.1",
4647
"php-http/cache-plugin": "<1.7",
4748
"php-http/curl-client": "<2.0",
4849
"php-http/socket-client": "<2.0",
49-
"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",

src/DependencyInjection/Configuration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,18 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
619619
->end()
620620
->end();
621621
// End error plugin
622+
623+
$throttle = $children->arrayNode('throttle')
624+
->canBeEnabled()
625+
->addDefaultsIfNotSet()
626+
->children()
627+
->scalarNode('name')->end()
628+
->scalarNode('key')->defaultNull()->end()
629+
->integerNode('tokens')->defaultValue(1)->end()
630+
->floatNode('max_time')->defaultNull()->end()
631+
->end()
632+
->end();
633+
// End throttle plugin
622634
}
623635

624636
/**

src/DependencyInjection/HttplugExtension.php

Lines changed: 22 additions & 1 deletion
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;
@@ -30,9 +31,11 @@
3031
use Symfony\Component\DependencyInjection\ChildDefinition;
3132
use Symfony\Component\DependencyInjection\ContainerBuilder;
3233
use Symfony\Component\DependencyInjection\Definition;
34+
use Symfony\Component\DependencyInjection\Extension\Extension;
3335
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
3436
use Symfony\Component\DependencyInjection\Reference;
35-
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
37+
use Symfony\Component\HttpKernel\Kernel;
38+
use Symfony\Component\RateLimiter\LimiterInterface;
3639
use Twig\Environment as TwigEnvironment;
3740

3841
/**
@@ -284,6 +287,24 @@ private function configurePluginByName($name, Definition $definition, array $con
284287

285288
break;
286289

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

289310
case 'add_host':

src/Resources/config/plugins.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<service id="httplug.plugin.stopwatch" class="Http\Client\Common\Plugin\StopwatchPlugin" public="false" abstract="true">
2929
<argument />
3030
</service>
31+
<service id="httplug.plugin.throttle" class="Http\Client\Common\Plugin\ThrottlePlugin" public="false" abstract="true">
32+
<argument />
33+
</service>
3134

3235
<!-- client specific plugin definition prototypes -->
3336

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ class ConfigurationTest extends AbstractExtensionConfigurationTestCase
8989
'enabled' => false,
9090
'only_server_exception' => false,
9191
],
92+
'throttle' => [
93+
'enabled' => false,
94+
'key' => null,
95+
'tokens' => 1,
96+
'max_time' => null,
97+
],
9298
],
9399
'discovery' => [
94100
'client' => 'auto',
@@ -293,6 +299,12 @@ public function testSupportsAllConfigFormats(): void
293299
'enabled' => false,
294300
'only_server_exception' => false,
295301
],
302+
'throttle' => [
303+
'enabled' => false,
304+
'key' => null,
305+
'tokens' => 1,
306+
'max_time' => null,
307+
],
296308
],
297309
'discovery' => [
298310
'client' => 'auto',

0 commit comments

Comments
 (0)