Skip to content

Commit 730ebb9

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

27 files changed

+148
-20
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:

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

+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 CurlFactory implements ClientFactory
1517
{

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

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

1212
/**
1313
* @author Tobias Nyholm <[email protected]>
14+
*
15+
* @final
1416
*/
1517
class SymfonyFactory implements ClientFactory
1618
{

src/Collector/Collector.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @author Fabien Bourigault <[email protected]>
1919
*
2020
* @internal
21+
* @final
2122
*/
2223
class Collector extends DataCollector
2324
{

src/Collector/Formatter.php

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* @author Fabien Bourigault <[email protected]>
2020
*
2121
* @internal
22+
* @final
2223
*/
2324
class Formatter implements MessageFormatter
2425
{

src/Collector/ProfileClient.php

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @author Fabien Bourigault <[email protected]>
2222
*
2323
* @internal
24+
* @final
2425
*/
2526
class ProfileClient implements ClientInterface, HttpAsyncClient
2627
{

src/Collector/ProfileClientFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @author Fabien Bourigault <[email protected]>
1717
*
1818
* @internal
19+
* @final
1920
*/
2021
class ProfileClientFactory implements ClientFactory
2122
{

src/Collector/ProfilePlugin.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @author Fabien Bourigault <[email protected]>
1616
*
1717
* @internal
18+
* @final
1819
*/
1920
class ProfilePlugin implements Plugin
2021
{

src/Collector/StackPlugin.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @author Fabien Bourigault <[email protected]>
1616
*
1717
* @internal
18+
* @final
1819
*/
1920
class StackPlugin implements Plugin
2021
{

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

+23
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,15 @@
3334
use Symfony\Component\DependencyInjection\Extension\Extension;
3435
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
3536
use Symfony\Component\DependencyInjection\Reference;
37+
use Symfony\Component\HttpKernel\Kernel;
38+
use Symfony\Component\RateLimiter\LimiterInterface;
3639
use Twig\Environment as TwigEnvironment;
3740

3841
/**
3942
* @author David Buchmann <[email protected]>
4043
* @author Tobias Nyholm <[email protected]>
44+
*
45+
* @final
4146
*/
4247
class HttplugExtension extends Extension
4348
{
@@ -279,6 +284,24 @@ private function configurePluginByName(string $name, Definition $definition, arr
279284

280285
break;
281286

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

284307
case 'add_host':

src/Discovery/ConfiguredClientsStrategy.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* we can use the web debug toolbar for clients found with the discovery.
1515
*
1616
* @author Tobias Nyholm <[email protected]>
17+
*
18+
* @final
1719
*/
1820
class ConfiguredClientsStrategy implements DiscoveryStrategy
1921
{

src/Discovery/ConfiguredClientsStrategyListener.php

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

1010
/**
1111
* @author Wouter de Jong <[email protected]>
12+
*
13+
* @final
1214
*/
1315
class ConfiguredClientsStrategyListener implements EventSubscriberInterface
1416
{

src/HttplugBundle.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/**
1010
* @author David Buchmann <[email protected]>
1111
* @author Tobias Nyholm <[email protected]>
12+
*
13+
* @final
1214
*/
1315
class HttplugBundle extends Bundle
1416
{

src/Resources/config/plugins.xml

+3
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

+12
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)