Skip to content

1 to 2 #461

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

Closed
wants to merge 14 commits into from
Closed
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
17 changes: 7 additions & 10 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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.*"
Expand All @@ -78,7 +75,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -88,18 +85,18 @@ 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"
if: "${{ matrix.stability == 'stable' }}"

- 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 }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ 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.

# 1.33.1 - 2024-05-27

- 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).
Expand Down
16 changes: 10 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -42,21 +42,25 @@
"symfony/options-resolver": "^5.4 || ^6.0 || ^7.0"
},
"conflict": {
"kriswallsmith/buzz": "<0.17",
"php-http/guzzle6-adapter": "<1.1",
"php-http/cache-plugin": "<1.7",
"php-http/curl-client": "<2.0",
"php-http/socket-client": "<2.0",
"kriswallsmith/buzz": "<0.17",
"php-http/react-adapter": "<3.0"
"php-http/react-adapter": "<3.0",
"php-http/throttle-plugin": "<1.1"
},
"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/throttle-plugin": "^1.1",
"php-http/mock-client": "^1.2",
"php-http/promise": "^1.0",
"phpunit/phpunit": "^9.6",
"symfony/browser-kit": "^5.4 || ^6.0 || ^7.0",
"symfony/cache": "^5.4 || ^6.0 || ^7.0",
"symfony/dom-crawler": "^5.4 || ^6.0 || ^7.0",
Expand Down Expand Up @@ -95,7 +99,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"
}
}
17 changes: 16 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,29 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
->end();
// End stopwatch plugin

$error = $children->arrayNode('error')
$children->arrayNode('error')
->canBeEnabled()
->addDefaultsIfNotSet()
->children()
->scalarNode('only_server_exception')->defaultFalse()->end()
->end()
->end();
// End error plugin

$children->arrayNode('throttle')
->canBeEnabled()
->addDefaultsIfNotSet()
->children()
->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()
->end()
->end();
// End throttle plugin
}

/**
Expand Down
21 changes: 20 additions & 1 deletion src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,9 +31,10 @@
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\RateLimiter\LimiterInterface;
use Twig\Environment as TwigEnvironment;

/**
Expand Down Expand Up @@ -284,6 +286,23 @@ 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".');
}

$container
->register($serviceId.$config['name'], LimiterInterface::class)
->setFactory([new Reference('limiter.'.$config['name']), 'create'])
->addArgument($config['key'])
->setPublic(false);

$definition->replaceArgument(0, new Reference($serviceId.$config['name']));
$definition->setArgument('$tokens', $config['tokens']);
$definition->setArgument('$maxTime', $config['max_time']);

break;

/* client specific plugins */

case 'add_host':
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<service id="httplug.plugin.stopwatch" class="Http\Client\Common\Plugin\StopwatchPlugin" public="false" abstract="true">
<argument />
</service>
<service id="httplug.plugin.throttle" class="Http\Client\Common\Plugin\ThrottlePlugin" public="false" abstract="true">
<argument />
</service>

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

Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class ConfigurationTest extends AbstractExtensionConfigurationTestCase
'enabled' => false,
'only_server_exception' => false,
],
'throttle' => [
'enabled' => false,
'key' => null,
'tokens' => 1,
'max_time' => null,
],
],
'discovery' => [
'client' => 'auto',
Expand Down Expand Up @@ -293,6 +299,12 @@ public function testSupportsAllConfigFormats(): void
'enabled' => false,
'only_server_exception' => false,
],
'throttle' => [
'enabled' => false,
'key' => null,
'tokens' => 1,
'max_time' => null,
],
],
'discovery' => [
'client' => 'auto',
Expand Down
12 changes: 9 additions & 3 deletions tests/Unit/DependencyInjection/HttplugExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public function testClientPlugins(): void
'headers' => ['X-FOO'],
],
],
[
'query_defaults' => [
'parameters' => ['locale' => 'en'],
],
],
[
'request_seekable_body' => [
'use_file_buffer' => true,
Expand All @@ -140,8 +145,8 @@ public function testClientPlugins(): void
'response_seekable_body' => true,
],
[
'query_defaults' => [
'parameters' => ['locale' => 'en'],
'throttle' => [
'name' => 'test',
],
],
[
Expand Down Expand Up @@ -179,9 +184,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',
Expand Down
Loading