From 7e545f8c5219a0bd7d106c082c4fc57fec872a4d Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 5 May 2024 12:33:57 +0200 Subject: [PATCH 1/9] install flex in shivammathur --- .github/workflows/continuous-integration.yml | 8 ++++---- .github/workflows/static-analysis.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b2a550e9..972b562e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -78,7 +78,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" with: fetch-depth: 2 @@ -88,6 +88,7 @@ jobs: php-version: "${{ matrix.php-version }}" coverage: "pcov" ini-values: "zend.assertions=1" + tools: "flex" - name: "Enforce using stable dependencies" run: "composer config minimum-stability stable" @@ -95,11 +96,10 @@ jobs: - name: "Add dependencies and enable flex" run: | - composer require --no-update symfony/flex ${{ matrix.dependencies }} - composer config --no-plugins allow-plugins.symfony/flex true + composer require --no-update ${{ matrix.dependencies }} - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: dependency-versions: "${{ matrix.dependency-versions }}" composer-options: "${{ matrix.composer-options }}" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 9703d7de..99c2b1f2 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -15,7 +15,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - name: "PHP-CS-Fixer" uses: "docker://oskarstark/php-cs-fixer-ga:2.19.0" with: From 2905f7e10250ff3992c442c0a5e9a474e4e20b88 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 22 May 2024 12:46:18 +0200 Subject: [PATCH 2/9] use extension class from di component instead of the kernel --- CHANGELOG.md | 4 ++++ src/DependencyInjection/HttplugExtension.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bfd08e6..fbd72e79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee # Version 1 +# unreleased + +- Fixed extension to depend on the DependencyInjection component rather than the HttpKernel. + # 1.33.0 - 2024-02-27 - 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). diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index a70e0b6c..3fea496c 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -31,9 +31,9 @@ use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\HttpKernel\Kernel; use Twig\Environment as TwigEnvironment; From b7ad2c1951edec36ef0bd9897e309b0038c59a54 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 27 May 2024 13:35:05 +0200 Subject: [PATCH 3/9] prepare release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbd72e79..f24cbc4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee # Version 1 -# unreleased +# 1.33.1 - 2024-05-27 - Fixed extension to depend on the DependencyInjection component rather than the HttpKernel. From 58223ebb719ef09dd721a581cde87ccfe95397a9 Mon Sep 17 00:00:00 2001 From: Maxim Date: Mon, 17 Jun 2024 10:05:08 +0200 Subject: [PATCH 4/9] add configuration for ThrottlePlugin (#460) --- composer.json | 3 ++- src/DependencyInjection/Configuration.php | 12 +++++++++++ src/DependencyInjection/HttplugExtension.php | 20 +++++++++++++++++++ src/Resources/config/plugins.xml | 3 +++ .../DependencyInjection/ConfigurationTest.php | 12 +++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 27111a4a..3daeef71 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "php-http/guzzle6-adapter": "<1.1", "php-http/cache-plugin": "<1.7.0", "php-http/curl-client": "<2.0", - "php-http/socket-client": "<2.0" + "php-http/socket-client": "<2.0", + "php-http/throttle-plugin": "<1.1" }, "require-dev": { "guzzlehttp/psr7": "^1.7 || ^2.0", diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 4b842990..bd70c712 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -624,6 +624,18 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA ->end() ->end(); // End error plugin + + $throttle = $children->arrayNode('throttle') + ->canBeEnabled() + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('name')->end() + ->scalarNode('key')->defaultNull()->end() + ->integerNode('tokens')->defaultValue(1)->end() + ->floatNode('max_time')->defaultNull()->end() + ->end() + ->end(); + // End throttle plugin } /** diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index 3fea496c..cdcbfcf0 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -10,6 +10,7 @@ use Http\Client\Common\HttpMethodsClient; use Http\Client\Common\HttpMethodsClientInterface; use Http\Client\Common\Plugin\AuthenticationPlugin; +use Http\Client\Common\Plugin\ThrottlePlugin; use Http\Client\Common\PluginClient; use Http\Client\Common\PluginClientFactory; use Http\Client\HttpAsyncClient; @@ -35,6 +36,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\RateLimiter\LimiterInterface; use Twig\Environment as TwigEnvironment; /** @@ -292,6 +294,24 @@ private function configurePluginByName($name, Definition $definition, array $con break; + case 'throttle': + if (!\class_exists(ThrottlePlugin::class)) { + throw new InvalidConfigurationException('You need to require the Throttle Plugin to be able to use it: "composer require php-http/throttle-plugin".'); + } + + $key = $config['name'] ? '.'.$config['name'] : ''; + $container + ->register($serviceId.$key, LimiterInterface::class) + ->setFactory([new Reference('limiter.'.$config['name']), 'create']) + ->addArgument($config['key']) + ->setPublic(false); + + $definition->replaceArgument(0, new Reference($serviceId.$key)); + $definition->setArgument('$tokens', $config['tokens']); + $definition->setArgument('$maxTime', $config['max_time']); + + break; + /* client specific plugins */ case 'add_host': diff --git a/src/Resources/config/plugins.xml b/src/Resources/config/plugins.xml index 749407c4..9f9c0ec1 100644 --- a/src/Resources/config/plugins.xml +++ b/src/Resources/config/plugins.xml @@ -28,6 +28,9 @@ + + + diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 447efe1a..999c813b 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -98,6 +98,12 @@ class ConfigurationTest extends AbstractExtensionConfigurationTestCase 'enabled' => false, 'only_server_exception' => false, ], + 'throttle' => [ + 'enabled' => false, + 'key' => null, + 'tokens' => 1, + 'max_time' => null, + ], ], 'discovery' => [ 'client' => 'auto', @@ -308,6 +314,12 @@ public function testSupportsAllConfigFormats(): void 'enabled' => false, 'only_server_exception' => false, ], + 'throttle' => [ + 'enabled' => false, + 'key' => null, + 'tokens' => 1, + 'max_time' => null, + ], ], 'discovery' => [ 'client' => 'auto', From 5380dadb3ca75be5aa54983db86e0e8fa4c7e7ca Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 17 Jun 2024 10:06:25 +0200 Subject: [PATCH 5/9] prepare release --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f24cbc4f..ccaff89d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee # Version 1 +# 1.34.0 - 2024-06-17 + +- Support to configure the throttle plugin. + # 1.33.1 - 2024-05-27 - Fixed extension to depend on the DependencyInjection component rather than the HttpKernel. From b8451d3f92fd024d5dc1b955b806bebb52b197e1 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 17 Jun 2024 10:16:58 +0200 Subject: [PATCH 6/9] add test for throttle plugin --- .github/workflows/continuous-integration.yml | 9 +++------ composer.json | 1 + .../DependencyInjection/HttplugExtensionTest.php | 12 ++++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7843f215..744eb5a4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -22,16 +22,13 @@ jobs: include: # Minimum supported Symfony version and lowest PHP version - dependencies: "php-http/guzzle7-adapter php-http/discovery:^1.12" - php-version: "7.3" + php-version: "7.4" dependency-versions: "lowest" symfony-deprecations-helper: "weak" stability: "stable" # Test the latest stable release - dependencies: "php-http/guzzle7-adapter php-http/vcr-plugin:^1.0@dev" - php-version: "7.3" - symfony-deprecations-helper: "weak" - - dependencies: "php-http/guzzle6-adapter" php-version: "7.4" symfony-deprecations-helper: "weak" - dependencies: "php-http/guzzle7-adapter" @@ -49,7 +46,7 @@ jobs: # Test with httplug 2.x clients - dependencies: "php-http/guzzle7-adapter php-http/curl-client:^2.0.0 php-http/vcr-plugin:^1.0@dev php-http/socket-client:^2.0" - php-version: "7.3" + php-version: "7.4" symfony-deprecations-helper: "weak" # Latest commit to master @@ -65,7 +62,7 @@ jobs: # Test maintained versions of Symfony - dependencies: "php-http/guzzle7-adapter symfony/http-client:^5.4" symfony-require: "5.4.*" - php-version: "7.3" + php-version: "7.4" symfony-deprecations-helper: "weak" - dependencies: "php-http/guzzle7-adapter symfony/http-client:^6.0" symfony-require: "6.3.*" diff --git a/composer.json b/composer.json index 352aa3c8..2419e9e1 100644 --- a/composer.json +++ b/composer.json @@ -56,6 +56,7 @@ "nyholm/nsa": "^1.1", "nyholm/psr7": "^1.2.1", "php-http/cache-plugin": "^1.7", + "php-http/throttle-plugin": "^1.1", "php-http/mock-client": "^1.2", "php-http/promise": "^1.0", "symfony/browser-kit": "^5.4 || ^6.0 || ^7.0", diff --git a/tests/Unit/DependencyInjection/HttplugExtensionTest.php b/tests/Unit/DependencyInjection/HttplugExtensionTest.php index b2895062..30fd5894 100644 --- a/tests/Unit/DependencyInjection/HttplugExtensionTest.php +++ b/tests/Unit/DependencyInjection/HttplugExtensionTest.php @@ -131,6 +131,11 @@ public function testClientPlugins(): void 'headers' => ['X-FOO'], ], ], + [ + 'query_defaults' => [ + 'parameters' => ['locale' => 'en'], + ], + ], [ 'request_seekable_body' => [ 'use_file_buffer' => true, @@ -140,9 +145,7 @@ public function testClientPlugins(): void 'response_seekable_body' => true, ], [ - 'query_defaults' => [ - 'parameters' => ['locale' => 'en'], - ], + 'throttle' => true, ], [ 'authentication' => [ @@ -179,9 +182,10 @@ public function testClientPlugins(): void 'httplug.client.acme.plugin.header_defaults', 'httplug.client.acme.plugin.header_set', 'httplug.client.acme.plugin.header_remove', + 'httplug.client.acme.plugin.query_defaults', 'httplug.client.acme.plugin.request_seekable_body', 'httplug.client.acme.plugin.response_seekable_body', - 'httplug.client.acme.plugin.query_defaults', + 'httplug.client.acme.plugin.throttle', 'httplug.client.acme.authentication.my_basic', 'httplug.client.acme.plugin.cache', 'httplug.client.acme.plugin.error', From 5c3e184b1e96058c074c8d20a09ee3a708ba1f50 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 1 Sep 2024 09:07:16 +0200 Subject: [PATCH 7/9] throttle plugin requires a name --- CHANGELOG.md | 4 ++++ src/DependencyInjection/Configuration.php | 9 ++++++--- src/DependencyInjection/HttplugExtension.php | 5 ++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccaff89d..a4012550 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee # Version 1 +# 1.34.1 - 2024-09-01 + +- The rate-limiter name in the throttle plugin configuration is required. + # 1.34.0 - 2024-06-17 - Support to configure the throttle plugin. diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index bd70c712..76b13751 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -616,7 +616,7 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA ->end(); // End stopwatch plugin - $error = $children->arrayNode('error') + $children->arrayNode('error') ->canBeEnabled() ->addDefaultsIfNotSet() ->children() @@ -625,11 +625,14 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA ->end(); // End error plugin - $throttle = $children->arrayNode('throttle') + $children->arrayNode('throttle') ->canBeEnabled() ->addDefaultsIfNotSet() ->children() - ->scalarNode('name')->end() + ->scalarNode('name') + ->info('The name of the configured symfony/rate-limiter to use') + ->isRequired() + ->end() ->scalarNode('key')->defaultNull()->end() ->integerNode('tokens')->defaultValue(1)->end() ->floatNode('max_time')->defaultNull()->end() diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index cdcbfcf0..ce88c008 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -299,14 +299,13 @@ private function configurePluginByName($name, Definition $definition, array $con throw new InvalidConfigurationException('You need to require the Throttle Plugin to be able to use it: "composer require php-http/throttle-plugin".'); } - $key = $config['name'] ? '.'.$config['name'] : ''; $container - ->register($serviceId.$key, LimiterInterface::class) + ->register($serviceId.$config['name'], LimiterInterface::class) ->setFactory([new Reference('limiter.'.$config['name']), 'create']) ->addArgument($config['key']) ->setPublic(false); - $definition->replaceArgument(0, new Reference($serviceId.$key)); + $definition->replaceArgument(0, new Reference($serviceId.$config['name'])); $definition->setArgument('$tokens', $config['tokens']); $definition->setArgument('$maxTime', $config['max_time']); From 64362f16b2aed00c5aedd4c8afcae0489e85f9e9 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 1 Sep 2024 09:16:43 +0200 Subject: [PATCH 8/9] fix build --- composer.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 3daeef71..adb2ed91 100644 --- a/composer.json +++ b/composer.json @@ -50,18 +50,19 @@ }, "require-dev": { "guzzlehttp/psr7": "^1.7 || ^2.0", - "matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0", + "matthiasnoback/symfony-config-test": "^4.3 || ^5.0", + "matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0", "nyholm/nsa": "^1.1", "nyholm/psr7": "^1.2.1", "php-http/cache-plugin": "^1.7", "php-http/mock-client": "^1.2", "php-http/promise": "^1.0", + "phpunit/phpunit": "^9.6", "symfony/browser-kit": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/cache": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/http-foundation": "^4.4.19 || ^5.0 || ^6.0 || ^7.0", - "symfony/phpunit-bridge": "^6.4.1", "symfony/stopwatch": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/web-profiler-bundle": "^4.4.19 || ^5.0 || ^6.0 || ^7.0", @@ -97,7 +98,7 @@ }, "prefer-stable": false, "scripts": { - "test": "vendor/bin/simple-phpunit", - "test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml" + "test": "vendor/bin/phpunit", + "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" } } From 818e189ca001839b8d101496fa37bb67e365d4ab Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 1 Sep 2024 09:44:17 +0200 Subject: [PATCH 9/9] adjust test to actual needs --- composer.json | 2 +- tests/Unit/DependencyInjection/HttplugExtensionTest.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f50784d8..1531180a 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } ], "require": { - "php": "^7.3 || ^8.0", + "php": "^7.4 || ^8.0", "php-http/client-common": "^2.0", "php-http/client-implementation": "^1.0", "php-http/discovery": "^1.14", diff --git a/tests/Unit/DependencyInjection/HttplugExtensionTest.php b/tests/Unit/DependencyInjection/HttplugExtensionTest.php index 30fd5894..08925375 100644 --- a/tests/Unit/DependencyInjection/HttplugExtensionTest.php +++ b/tests/Unit/DependencyInjection/HttplugExtensionTest.php @@ -145,7 +145,9 @@ public function testClientPlugins(): void 'response_seekable_body' => true, ], [ - 'throttle' => true, + 'throttle' => [ + 'name' => 'test', + ], ], [ 'authentication' => [